Williams Williams - 9 months ago 73
Java Question

Error : org.apache.http.client.HttpResponseException: Unsupported Media Type

I am trying to call web api using http://loopj.com/android-async-http/ & using

method. I am sending json & content type in my code that's always gives error message.

org.apache.http.client.HttpResponseException: Unsupported Media Type

When I test same in the rest client using same json & content type its works fine. I don't know what more I need to set to execute it correctly.

Please see my below code.

// creating JSON using GSON library
Login mLogin = new Login();

Gson gson = new GsonBuilder().create();
String loginJSON = gson.toJson(mLogin);

mHttpEntity = new StringEntity(loginJSON);

// execute the http asynchronously using post http method
asyncHttpClient.post(getActivity(), URL, mHttpEntity, "application/json", new AsyncHttpResponseHandler() {
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
Logger.d(TAG, responseBody.toString());

public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
Logger.d(TAG, responseBody.toString());

Thanks in advance.


If you're getting, org.apache.http.client.HttpResponseException: Unsupported Media Type in your app but not in a REST client, then the problem likely has to do with you putting extra things in the POST activity. The server is probably receiving too many (or possibly too few) parameters and therefore is sending back a bad response.

Without seeing your actual post, I can't pinpoint exactly where the problem is, but my suggestion is to try to see what the server is receiving from your POST and make sure that the items you send in the Android POST match the REST API Client POST exactly.