我想用java登錄到網站。我用的是org.apache.http,我已經寫了用java登錄網站
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://accounts.google.com/ServiceLogin? service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fhl%3Dsl%26tab%3Dwm%26ui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1<mpl=default&");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("vb_login_username",
"XXX"));
nameValuePairs.add(new BasicNameValuePair("vb_login_password",
"XXX"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
它發出的帖子形式正確我已經測試過,但我仍然無法登錄。我想登錄的網站是http://www.xtratime.org/forum/對此有任何想法或是有不同的方式嗎?
爲什麼會有所有thos在URL中'?'之後的空格? –
您的代碼中的網址與您的目標網站的網址不匹配。那不就是一隻紅鯡魚嗎? – BalusC
什麼是HttpResponse?響應碼是200嗎?返回的HTML仍然是登錄頁面? – jeff