我正在开发一个 Android 应用程序,我需要登录到一个网页。为此,我使用 HttpPost。这就是我正在做的事情:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://202.163.117.123:8080/hitrack/default.aspx");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("__EVENTTARGET", ""));
nameValuePairs.add(new BasicNameValuePair("__EVENTARGUMENT", ""));
nameValuePairs.add(new BasicNameValuePair("username", "user123"));
nameValuePairs.add(new BasicNameValuePair("Password", "pass456"));
nameValuePairs.add(new BasicNameValuePair("ButtonLogin0", "Login"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
Log.d("response",responseBody);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但这向我展示了相同 loginPage 的来源。为什么它不重定向到其他页面?我是否必须添加重定向处理程序。如果是,那么我是否要实施它?
我试过了,但这也没有用。