android - Post JsonObject with Volley -
i'm trying send post request volley without success.
the lib working correctly, , manage sent string requests, post jsonobject doesn't work.
string urljsonreq = "https://api.parse.com/1/classes/gamescore"; string tag_json_obj = "tag_json"; jsonobjectrequest jsonreq = new jsonobjectrequest(request.method.post, urljsonreq, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d("myapp", response.tostring()); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d("myapp", "error: " + error.getmessage()); // hide progress dialog } }) { @override protected map<string, string> getparams() { map<string, string> params = new hashmap<string, string>(); params.put("value1", "testvalue1"); params.put("value2", "testvalue2"); return params; } @override public map<string, string> getheaders() throws authfailureerror { hashmap<string, string> headers = new hashmap<string, string>(); headers.put("x-parse-rest-api-key", "xxxxxxxxxxxx"); headers.put("x-parse-application-id", "xxxxxxxxxxx"); return headers; } @override public string getbodycontenttype() { return "application/json"; } };
i keep getting error. read somewhere, without details volley cannot sent jsonobjects, receive then. if want solve problem should implement custom class, don't know if i'm making stupid mistake here (it possible).
do guys know that?
thank time.
you can send jsonobject without overiding getparams or getbodycontenttype. example
jsonobject object = new jsonobject(); jsonobjectrequest jr = new jsonobjectrequest(request.method.post, url, object, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { } });
obviously can override headers if need to.
Comments
Post a Comment