Android 如何获取重定向页面URL Httpclient
下面的代码帮助我登录到一个页面,并获取重定向页面的所有Html内容。但是,当我获取url时,它会提供旧的登录url 如何获取重定向的页面URLAndroid 如何获取重定向页面URL Httpclient,android,Android,下面的代码帮助我登录到一个页面,并获取重定向页面的所有Html内容。但是,当我获取url时,它会提供旧的登录url 如何获取重定向的页面URL protected Void doInBackground(String... params) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(UrlLink); try { // Add
protected Void doInBackground(String... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(UrlLink);
try {
// Add user name and password
String username = "xxxxxxx";
String password = "yyyyyyy";
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("login", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.v("SENCIDE", "Execute HTTP Post Request");
HttpResponse response = httpclient.execute(httppost);
InputStream is=response.getEntity().getContent();
old --->String newUrl=httppost.getURI().toString();
Url Log.v("ddd",newUrl);
String line = "";
StringBuilder total = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
Log.v("dfd",total.toString());
} catch (IOException e) {
e.printStackTrace();
}
查看响应的位置headerNot无法理解can u plz..应该类似于以下字符串redirectURL=response.getFirstHeaderLocation.getValue;让我知道,这样我就可以发布它作为答案。如果我插入该行,它会抛出错误消息