我想從需要在頁面中登錄的網頁獲取一些數據。我可以用htmlunit做,但給我的問題在Android上導入這些庫。所以我試圖用apache http客戶端來做到這一點。Android登錄和重定向
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://inside.cineca.it/cgi-bin/uinside/marcature.pl");
BasicNameValuePair usernameBasicNameValuePair = new BasicNameValuePair("j_username", "user");
BasicNameValuePair passwordBasicNameValuePAir = new BasicNameValuePair("j_password", "pass");
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
nameValuePairList.add(usernameBasicNameValuePair);
nameValuePairList.add(passwordBasicNameValuePAir);
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairList);
HttpResponse httpResponse = httpClient.execute(httpPost);
System.out.println(EntityUtils.toString(httpResponse.getEntity()));
但是給我錯誤。我很害怕我應該管理重定向,但我不知道如何。如果有人能給我一些建議,我會很高興。 致以問候
請給出錯誤日誌。 – guydemossyrock