我正在尝试登录以下网站: http: //www.deeproute.com。登录表单字段如下:
<input type="hidden" name="cookieexists" value="false">
<input size=12 type=name name=name>
<input size=12 type=password name=password>
<input type=submit name=subbera value="Login">
这是我尝试使用 HttpClient 登录并使用 Jsoup 解析生成的 html 的代码。不幸的是,这会以相同的未登录状态返回页面的原始 html。
HttpResponse res = null;
Document homePage = null;
HttpEntity entity = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.deeproute.com");
String html = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("cookieexists", "false"));
nameValuePairs.add(new BasicNameValuePair("name", username));
nameValuePairs.add(new BasicNameValuePair("password", pass));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
res = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
if (res != null) {
try {
html = EntityUtils.toString(res.getEntity());
homePage = Jsoup.parse(html);
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我能做些什么来解决这个问题?