我正在尝试测试以下页面是否http://support.xbox.com/en-US/xbox-360/console-freeze/screen-freeze-wizard。该页面重定向到http://support.xbox.com/en-US/xbox-360/console-freeze/screen-freeze-solution但是标题中没有显示。
我的应用程序检查页面 URL 状态',遵循此重定向并检查它是否以 404 或 200 结尾的最佳/最快方式是什么。
编辑:当我使用 fiddler2 检查页面标题时,我得到以下信息:
HTTP/1.1 301 Moved Permanently
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html
Expires: -1
Location: /en-US/xbox-360/console-freeze/screen-freeze-solution
X-UA-Compatible: IE=edge
X-Content-Type-Options: nosniff
Content-Length: 0
Vary: Accept-Encoding
Date: Mon, 03 Sep 2012 15:14:16 GMT
Connection: keep-alive
这给出了重定向。我的代码如下
public void status() {
HttpClient hc = new DefaultHttpClient();
HttpHead hh = new HttpHead("http://support.xbox.com/en-US/xbox-360/console-freeze/screen-freeze-wizard");
System.out.println("Requesting : " + hh.getURI());
try {
HttpResponse response = hc.execute(hh);
System.out.println("Protocol : " + response.getProtocolVersion());
System.out.println("Status code : " + response.getStatusLine().getStatusCode());
Header [] headers = response.getAllHeaders();
for (Header header : headers) {
System.out.println(" --> " + header.getName() + ":" + header.getValue());
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
但它只给出以下响应:
Requesting : http://support.xbox.com/en-US/xbox-360/console-freeze/screen-freeze-wizard
Protocol : HTTP/1.1
Status code : 404
--> Cache-Control:private
--> Content-Length:0
--> X-Content-Type-Options:nosniff
--> Date:Mon, 03 Sep 2012 15:23:59 GMT
--> Connection:keep-alive
...complete.