如何通过Android应用程序登录网站(http://www.myhopaccount.co.nz/CWP/ - - - - 您将被重定向到实际网站)?我已经看过几乎所有问题了。每当我发送数据时,当我检索信息时,我总是从登录页面获取信息。
有人可以通过应用程序向我显示用于登录该网站的代码,或者将我链接到某个有用的地方吗?我尝试了不同的方法(jsoup,httpclient),但仍然没有。
这是我最近的尝试:(用户名/密码是从文本字段中获取的)
Thread thread = new Thread() {
public void run() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myhopaccount.co.nz/CWP/");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(newBasicNameValuePair("ctl00$contentPlaceHolder$UsernameTextBox", username));
nameValuePairs.add(new BasicNameValuePair("ctl00$contentPlaceHolder$PasswordTextBox", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.v("StatusCode", "Response from server: " + response.getStatusLine().getStatusCode());
} catch (ClientProtocolException e) {
System.out.println("CPE: " + e.getMessage());
} catch (IOException e) {
System.out.println("IOE: " + e.getMessage());
}
}
};
thread.start();
在此之前,我尝试了这个解决方案:Performing login to https website via Android app
但是,它只返回登录页面的源代码。