android - Wrong Content type Error when Posting to Parse.com RestAPI -
good day, been struggling bit , not sure anymore. using android asynchronus http library here send post parse keep getting error message.
{"code":107,"error":"this endpoint supports content-type: application/json requests, not application/x-www-form-urlencoded."}
here relevant parts of code:
client = new asynchttpclient(); client.addheader("content-type", "application/json"); client.addheader("x-parse-application-id", context.getresources().getstring(r.string.app_id)); client.addheader("x-parse-rest-api-key", context.getresources().getstring(r.string.rest_api_key)); requestparams params = null; jsonobject json = new jsonobject(); try { json.put(name, player_text.gettext().tostring()); json.put(club, club_text.gettext().tostring()); } catch (jsonexception e) { e.printstacktrace(); } params = new requestparams("json",json); //takes key value pair client.post(context, url, params, responsehandler); // posting https://api.parse.com/1/classes/abcder/
i have set header content-type application/json don't know why getting error. have requested getcontenttype params see , gives me error parse complaining about. doing wrong? highly appreciated. in advance
the json needs posted data/body, not encoded in url parameters.
here's answer shows how: posting json/xml using android-async-http (loopj)
so you:
jsonobject json = new jsonobject(); try { json.put(name, player_text.gettext().tostring()); json.put(club, club_text.gettext().tostring()); } catch (jsonexception e) { e.printstacktrace(); } stringentity body = new stringentity(json.tostring()); client.post(context, url, body, "application/json", responsehandler);
Comments
Post a Comment