我在 Apache 日志中看到了这一点。基本上,请求来自 Android Emulator,使用HTTPUrlConnection
. 这是我的代码。
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;
我正在发送用户代理标头以确保服务器没有过滤不可识别的用户代理。我使用 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
。
有人有什么想法吗?