This is the Post Request done using postman
The response I want to get is :
{
"result": "success",
"reason": {
"first_name": "aswath",
"last_name": "AsH",
"email": "[email protected]",
"phone": ""8867336754"",
"authy_id": "26829982",
"updated_at": "2016-09-27 06:38:07",
"created_at": "2016-09-27 06:38:07",
"id": "5012"
},
"sms": "token sent"
}
This is the Request I am trying to send :
JSONObject jsonBody = new JSONObject();
jsonBody.put("first_name", firstname);
jsonBody.put("last_name", lastName);
jsonBody.put("email", Email);
jsonBody.put("phone", number);
final String mRequestBody = jsonBody.toString();
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("VOLLEY", response);
Log.d("**********", "FETCHING IN VOLLEY REQ" + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", error.toString());
}
}) {
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
@Override
public byte[] getBody() throws AuthFailureError {
try {
return mRequestBody == null ? null : mRequestBody.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", mRequestBody, "utf-8");
return null;
}
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError
{
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "multipart/form-data");
return headers;
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String responseString = "";
if (response != null) {
responseString = String.valueOf(response.statusCode);
// can get more details such as response.headers
}
return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
}
};
getRequestOtpPage().addToRequestQueue(stringRequest);
But when i post request it returns the error!
How to solve the problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…