0
I need to get a server Bitmap through a POST method with the body (JSON) and header to put in an Imageview.
I tried using Volley’s Imagerequest but I would need to pass the URL directly from my image, which does not occur. I have a URL with some parameters and a JSON body (which sends the data of the image I’m looking for) and the server would bring me the image if I found it but I’m getting a 405 error.
I tried the same method by Postman and managed to get the image without problems.
My code:
RequestQueue sQueueFoto = Volley.newRequestQueue(getActivity());
//REQUEST FOTO
String sEnderecoBaseFoto = Variaveis.WebServicePocket + "/api/Imagem/PegarImagem?redeCodigo=" + Variaveis.Rede + "&largura=120&altura=120";
ImageRequest sRequestFoto = new ImageRequest(sEnderecoBaseFoto,
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap)
{
sProdutos.getDadosProduto().setImagemProduto(bitmap);
}
}, 0, 0, null,
new Response.ErrorListener()
{
public void onErrorResponse(VolleyError error) {
Mensagem.ExibirAlert(getActivity(), String.valueOf(error.networkResponse.statusCode));
}
})
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> sHeaders = new HashMap<>();
sHeaders.put("Authorization", "Bearer " + Variaveis.WebServicePocketToken);
return sHeaders;
}
@Override
public byte[] getBody() throws AuthFailureError
{
return new Gson().toJson(infoImagem).getBytes();
}
@Override
public String getBodyContentType() {
return "application/json";
}
};
sQueueFoto.add(sRequestFoto);