有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Android/Java“org.apache.http.ProtocolException”,http头应答有问题

早上好, 几周来,我一直在尝试使用Android从网页上获取一些数据。通常我对此没有任何问题。但在这种情况下,服务器不会返回标准HTTP应答

为了给你一个想法,它应该回答这样的问题:

Status=OK - 200
Date=Thu, 23 Dec 2011 10:16:17 GMT
Server=Apache/2.2.14 (Ubuntu)
X-Powered-By=PHP/5.3.2-1ubuntu4.9
Vary=Accept-Encoding
Content-Encoding=gzip
Content-Length=49
Keep-Alive=timeout=15, max=96
Connection=Keep-Alive
Content-Type=text/html
...

但这只是回答:

Status=OK - 200
...

所以我认为这就是我得到这个错误的原因:

W/System.err(18227): Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response

我曾经尝试过许多不同的方法,但似乎没有一种能与此Web服务器配合使用(即使我可以用浏览器阅读页面)。 我还尝试运行脚本并从其他Web服务器读取其他网页,脚本工作正常。但是无法使它与此Web服务器一起工作(因为http应答)

我用了这个方法:

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(urlAddress));
HttpResponse response = client.execute(request);

还有这个

URL url = new URL(urlAddress);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

我无法更改Web服务器。。。你有什么办法能帮上忙吗

非常感谢您抽出时间


共 (0) 个答案