ClientProtocolException in httpClient.execute(httpget, responseHandler)
As your code seems to be correct, you have to figure out: Is this the client's fault (invalid request), or the server's fault (invalid response). To do that, use a http trace utitlity and compare the requests of a browser to that of your client. You'll also be able to see the raw response from the server, if there is any. If you can't figure it out then, add the raw request and response to your question and someone might be able to help.
I have tested your code with my ip address. There is no error in code. I just changed ResponseHandler
to BasicResponseHandler
.
check this
HttpClient httpclient = new DefaultHttpClient();
try
{
HttpGet httpget = new HttpGet("http://www.MyServer.com/get_public_tbl.cgi?A=1");
BasicResponseHandler responseHandler = new BasicResponseHandler();//Here is the change
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println(responseBody);
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
httpclient.getConnectionManager().shutdown();
}
You could try to add your own response interceptor, where you can add or delete headers, or print some debug info
hc.addResponseInterceptor(new HttpResponseInterceptor() {
@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
response.getEntity().writeTo(System.out);
}
});