以下代码可以帮助我登录页面并获取重定向页面的所有Html内容。但是,当我收到网址时,它会给我旧的登录网址。
如何获取重定向的网页网址?
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();
}