Post Nested Json Object To Server Using Volley Getting Response 200
Solution 1:
As my comments, you can refer to the sample code at my answer at the following question (pay attention to getBody()
. If the response from your web service is a JSONObject
, you can use JsonObjectRequest
instead of StringRequest
)
Solution 2:
this way you should make your JSON
JSONObject jsonWholeObject = newJSONObject();
JSONObject jsonFaceBook = newJSONObject();
try {
jsonFaceBook.put("age", "28");
jsonFaceBook.put("birthday", "563221800");
jsonFaceBook.put("first_name", "Bradley");
jsonFaceBook.put("gender", "male");
jsonFaceBook.put("provider", "Facebook");
} catch (JSONException e) {
e.printStackTrace();
}
jsonWholeObject.put("email", "steve123@gmail.com" );
jsonWholeObject.put("loginData", jsonFaceBook);
Then you can use it in a volley request
Solution 3:
@OverridepublicMap<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = newHashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
this is to attache Headers with volley during a get/post request. This should be the token that facebook have provided you as response, when you tried to login through facebook login in your android application.
consider this, you will get a token like this for successful login.
token = "xyz" After successful login you have to attach this token with header on every request you make. This is identified at server end. So don't send a empty header. It should be something like this.
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("token","bearer + "" +yourtoken)
return params;
}
};
Give it a try.
Post a Comment for "Post Nested Json Object To Server Using Volley Getting Response 200"