ClientProtocolException在httpClient.execute(HTTPGET,ResponseHandler所) [英] ClientProtocolException in httpClient.execute(httpget, responseHandler)

查看:635
本文介绍了ClientProtocolException在httpClient.execute(HTTPGET,ResponseHandler所)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的code请求从Web服务器的xml:

I am using the following code to request xml from a web server:

HttpClient httpclient = new DefaultHttpClient()
try 
{
    HttpGet httpget = new HttpGet("http://63.255.173.242/get_public_tbl.cgi?A=1");              
    ResponseHandler responseHandler = new BasicResponseHandler();
    String responseBody = httpclient.execute(httpget, responseHandler);
    System.out.println(responseBody);
}
catch (ClientProtocolException e)
{
    e.printStackTrace();
}
catch (IOException e)
{
    e.printStackTrace();
} 
finally 
{
    httpclient.getConnectionManager().shutdown();
}

我得到一个clientProtocolException当我打电话httpclient.execute(HTTPGET,ResponseHandler所)。该网址的作品就好在Web浏览器,它返回的XML和浏览器中显示。

I get a clientProtocolException when I call httpclient.execute(httpget, responseHandler). The url works just fine in a web browser, it returns the xml and the browser displays it.

任何想法,为什么我会得到一个clientProtocolException,但浏览器处理它就好了?

Any ideas why I would get a clientProtocolException and yet the browser handles it just fine?

编辑1:

综观协议异常的详细消息是:服务器无法使用有效的HTTP响应应对。我无法改变,我打的Web服务器。有没有办法忽略这一点,只需访问响应?

Looking at the protocol exception the detail message is: "The server failed to respond with a valid HTTP response". I cannot change the web server that I am hitting. Is there a way to ignore this and just access the response?

编辑2:

我发现服务器没有发回一个完整的头。有没有一种方法来访问,即使返回一个破头的响应的内容?

I have found that the server is not sending back a complete header. Is there a way to access the contents of the response even when a broken header is returned?

编辑3:我编辑的ip地址是真实IP地址,我打。任何帮助将是非常美联社preciated。

Edit 3: I edited the ip address to be the real IP address I am hitting. Any help would be much appreciated.

推荐答案

随着code似乎是正确的,你要搞清楚:这是客户的错(无效的请求),或服务器的故障(失效响应)。要做到这一点,使用 HTTP跟踪utitlity 和比较器的该请求你的客户。您还可以看到来自服务器的原始响应,如果有的话。如果你不能弄清楚,然后,添加原始请求和响应你的问题,有人也许能有所帮助。

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.

这篇关于ClientProtocolException在httpClient.execute(HTTPGET,ResponseHandler所)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆