我通過httpclient的get方法訪問
在java環境下測試都沒問題
可是在安卓SDK環境下 卻得不到response的location
通過抓包分析
httpclient的實例執行get請求後
所以最後得到的response是重定向之後地址的get請求的response
這個時候需要阻止HttpClient的自動重定向
public static String getLocationMethod(String reqUrl
DefaultHttpClient httpclient = new DefaultHttpClient();
String location = null;
int responseCode =
try {
final HttpGet request = new HttpGet(reqUrl);
HttpParams params = new BasicHttpParams();
params
// 這樣就能拿到Location頭了
request
HttpResponse response = (request);
responseCode = response
Header[] headers = response
if(responseCode==
Header locationHeader = response
if (locationHeader != null) {
location = locationHeader
}
}
} catch (Exception e) {
e
MyLog
}
return location;
}
添加 params
ResponseCode=
Date:Sun
Server:Abloomy Http Server
Connection:Close
Cache
Pragma:no
Last
Content
Content
Expires:Mon
Location:?wlanacip=
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26007.html