我在Apache日志中看到了这一点。基本上,请求是使用HTTPUrlConnection从Android Emulator发出的。这是我的代码。
URL url = new URL(strUrl);
Log.d(params[0],"UR");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "Basic " + Base64.encodeToString(toencode, Base64.DEFAULT));
conn.setRequestProperty("Host", "www.domain.com");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.3.1)");
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setRequestMethod("GET");
conn.setConnectTimeout (30000) ;
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
String data = conn.getInputStream().toString();
return data;我发送user-agent标头,以确保服务器没有过滤不可识别的用户代理。我使用Wireshark捕获流量。这个请求似乎是可以的。不知道还能找什么。花了几个小时在这上面却没有运气。
GET Authenticate/ HTTP/1.1\r\n
Host: www.domain.com\r\n
User-Agent: Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.3.1)\r\n
Accept-Charset: UTF-8\r\n
Connection: Keep-Alive\r\n
Accept-Encoding: gzip\r\n
\r\n来自服务器的响应:
Request Version: HTTP/1.1
Status Code: 400
Response Phrase: Bad Request
<h1>Bad Request</h1>\n
<p>Your browser sent a request that this server could not understand.<br />\n在apache日志中:
client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23)在这一点上,我觉得我需要回到HttpClient并尝试一下。我想我应该使用HttpUrlConnection,因为谷歌推荐它。但我和HttpURLConnection的关系不太好。
有谁知道吗?
发布于 2012-09-15 13:16:44
仿真器未正确发送主机标头。所以我收到了来自服务器的错误请求。Wireshark帮助我解决了这个问题。
https://stackoverflow.com/questions/12418458
复制相似问题