下面的程序不斷輸出原始登錄頁面的源代碼在POINT B.爲什麼會發生這種情況?我怎樣才能解決這個問題?想要下一個網頁的數據應該出現。試圖登錄到網站...變得有點困惑
<form method="POST" name="logonform" action="/check-443/logon.logonform" autocomplete="off">
<input type="hidden" name="CDT" value="12313">
<input type="hidden" name="NEW_PASSWORD" value="">
<tr>
<td class="content">
<label for="User">Username</label>
</td>
<td>
<input type="text" name="LOGON" id="id" value="" size="15" maxlength="15">
</td>
</tr>
<tr>
<td class="content">
<label for="pass">Password:</label>
</td>
<td>
<input type="password" name="PASSWORDS" id="pw" value="" size="15">
</td>
</tr>
<tr>
<td>
<input type="submit" value="Log In">
</td>
</form>
我的代碼似乎沒有工作(我看到這個網上,並認爲這可能是適用)
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://abc.cba.com");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "Username"));
nameValuePairs.add(new BasicNameValuePair("pw", "*****"));
nameValuePairs.add(new BasicNameValuePair("Log In", "Log In"));
try {
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nameValuePairs);
httppost.setEntity(p_entity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
int status_code = response.getStatusLine().getStatusCode();
if (status_code >= 300) {
Log.d("asf", "Error"); //POINT A***************
return false;
} else {
Log.d("asf", EntityUtils.toString(entity)); //POINT B***************
return true;
}
} catch (Exception uee){}
return false;
@Chris:謝謝你打掃這個貼子。我不知道如何發佈。 – bluejamesbond 2012-01-30 08:40:08