I am working in android app that needs to get a token from a web api through POST request, I am using OkHttp library version 2.3.0 but strangely the post method is executing GET request as the result I am getting 405 status code which is method not allowed response from the server.
Here's my code.
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public String executePOST(){
OkHttpClient client = new OkHttpClient();
.
.
.
.
String url = API_URL + "/oauth/access_token/";
String strResponse = null;
RequestBody body = RequestBody.create(JSON, jsonBody);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response;
try {
response = client.newCall(request).execute();
strResponse = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
return strResponse;
}
When I debug the code the response object has this content...

Any idea what's the problem with this? What is the possible work around for this one? Your help will be greatly appreciated! Thanks...
I had this kind of problem when i send POST to http:// and not https://.
I suppose, it automatically redirected me to https:// where the method type was lost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With