1

Good day, been struggling a bit with this and not sure what to do anymore. I am using the android Asynchronus Http Library here to send a POST to parse but i keep getting this error message.

 {"code":107,"error":"This endpoint only supports Content-Type: application/json requests, not application/x-www-form-urlencoded."}

here are the relevant parts of my 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 a key value pair

   client.post(context, url, params, responsehandler); // posting to https://api.parse.com/1/classes/ABCDER/

i have set the header content-type to application/json so i don't know why i am getting the error. i have also requested the getContentType from the params to see and it gives me the error PARSE was complaining about. What could i be doing wrong? Any help is highly Appreciated. Thanks in advance

1 Answer 1

0

The JSON needs to be posted as the data/body, not encoded in the URL parameters.

Here's another answer that shows how: POSTing JSON/XML using android-async-http (loopj)

So for 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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! sorry i was away and couldn't respond earlier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.