Reputation: 3
I am trying to POST
authorization token in header using OkHttp
. I am trying something like this, but unfortunately, i've got 415 error
in debug mode. Thanks in advance.
private void Logout() throws IOException{
String postBody = "test post";
OkHttpClient okHttpClient= new OkHttpClient();
RequestBody body = RequestBody.create(
MediaType.parse("text/x-markdown"), postBody);
Request request = new Request.Builder()
.url("ABC")
.addHeader("Authorization",tokenBearer)
.post(body)
.build();
okHttpClient.newCall(request).enqueue(new okhttp3.Callback() {
@Override
public void onFailure(okhttp3.Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException {
if(response.isSuccessful()){
String message= response.body().toString();
Toast.makeText(getActivity(),message,Toast.LENGTH_LONG).show();
}
}
});
Upvotes: 0
Views: 397
Reputation: 347
415 code stands for unsupported media type. Here is what you can do in this case:
If you have such a possibility, consider using application/json
or something like that. Usually APIs have such option.
text/x-markdown
is not used widely, try to replace it with text/markdown
.
If nothing works for you, try getting text/plain
and create a small parcer that will process markdown
Upvotes: 1