LoopJ AndroidAsyncHttp returns code 415 when specifying RequestParams

822 views Asked by At

I'm using LoopJ AndroidAsyncHttp to post async Http calls from my android app. When i specify some RequestParams, the call keep failing, with a statusCode 415(Unsupported Media Type). As soon as i remove the requestParams the call goes through, without any error.

final AsyncHttpClient client;
String url = "http://someURL.com/SomeUserGUID/Profile/Statistics/Setup";
client = new AsyncHttpClient();

final RequestParams params = new RequestParams();
params.put("FirstClub", "false");
params.put("FairwayHit", "false");

Header[] headers = {
    new BasicHeader("Accept-Language", Locale.getDefault().toString())
    ,new BasicHeader("Authorization", ApplicationObject.companyBasicAuthString)
    ,new BasicHeader("Accept", "application/json")
};

client.setTimeout(60000);

client.post( ProfileActivity.this,url, headers, params, "application/json", new     AsyncHttpResponseHandler() {

@Override
public void onStart() {
    //Do something before start
    super.onStart();
}

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
    //some code
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
    //some code
}
});

My goal is for the URL to look like this: String url = http://someURL.com/SomeUserGUID/Profile/Statistics/Setup?FirstClub=false& FairwayHit=false

I would pref not to hard code the URL into one single string(This method works btw), because i have some calls that would create a really long URL string.

So how can i achieve a successful post call, with params, using AndroidAsyncHttp?

1

There are 1 answers

0
JstnPwll On

415 Unsupported Media Type

The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.

You're sending the Content-Type header (in your post call) as "application/json", but the params you've added are not JSON. This is probably why the error occurs.