Android Http Request Clientprotocolexception
I have an API that seems to be working perfect when I test it using Firefox's 'REST Client' or Google Chrome's 'Simple REST Client' However, when I send an Http request using Andro
Solution 1:
Your code seems to be correct.
ClientProtocolException
happens if there is an INVALID REQUEST
from the client or an INVALID RESPONSE
from the server
Also you have specified httpPost.setHeader("Accept", "application/json");
it expects that the server is returning an JSON
response. See docs for more details.
So you may check what response you are sending from the server. It should be a JSON response.
Or you can try removing httpPost.setHeader("Accept", "application/json");
and check what response you are getting.
Solution 2:
This should work
HttpParams httpParams=newBasicHttpParams();
DefaultHttpClienthttpClient=newDefaultHttpClient(httpParams);
HttpResponsehttpResponse=null;
HttpPosthttpPost=newHttpPost(Constants.URL);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Accept", "application/json");
StringEntityse=newStringEntity(params,HTTP.UTF_8);
httpPost.setEntity(se);
httpClient.execute(httpPost);
Post a Comment for "Android Http Request Clientprotocolexception"