I am sending a request to server and getting Collection + Json in responce. Every thing is perfect in PostMan.
But when I am doing same things in code using OKHTTP, I am getting some unreadable characters.
Here is my code
OkHttpClient client = new OkHttpClient();
requestBody = new FormBody.Builder()
.add("email", email)
.add("password", psd)
.build();
Request request = new Request.Builder()
.url(url)
.addHeader("Accept", "application/vnd.collection+json")
.addHeader("Accept-Encoding", "gzip")
.addHeader("Authorization", "Basic YWRtaW46cmVhbHNlYw==")
.post(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
String s = response.body().string();
response.body().close();
} catch (Exception e) {
e.printStackTrace();
}
I tried some other url and those are working perfect.
many thanks.
Finally I solved the issue and it wasn't very difficult one although I tried lot's of difficult approaches :P
I solved the issue by removing this line from the code
.addHeader("Accept-Encoding", "gzip")
hope it help to some one other who got stuck like me.
Thanks
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