Tuesday, 20 September 2016

rest - Android : Sending form-data as body Google Volley

In my Android application, I am using google's volley for network operations. There is a case where I need to make a request but send body as form-data.
I have tried everything else, but I am not able to make the request as form-data.



Here is a curl



curl -X POST -H "Content-Type: multipart/form-data" -F "mobile_number=" ""


How can I achieve that -F part in volley? The Server is throwing bad request.




This is what I have done :



final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, URLFactory.OTP_URL,
null, listener, errorListener){

@Override
public byte[] getBody() {
final JSONObject jsonObject = new JSONObject();
try {

jsonObject.put("mobile_number", mobileNumber);
} catch (JSONException e) {
e.printStackTrace();
return null;
}
return jsonObject.toString().getBytes();
}


@Override

public Map getHeaders() throws AuthFailureError {
final HashMap headers = new HashMap<>();
headers.put("Content-Type", "multipart/form-data");
return headers;
}
};


Please help me in this.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...