0
我想用http和apache客戶端登錄到一個網站,使用java和eclipse。我曾嘗試編寫代碼的方法很多,但它仍然不能正常工作:無法登錄網站
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
post = new HttpPost("http://www.biketrial.kiev.ua/forum/ucp.php?mode=login");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
String login = new String(log.getBytes("UTF-8"));
String pas =new String(password.getBytes("UTF-8"));
params.add(new BasicNameValuePair("username",login));
params.add(new BasicNameValuePair("password", pas));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
response = client.execute(post,localContext);
entity = response.getEntity();
BufferedReader br=new BufferedReader(new InputStreamReader(entity.getContent()));
String line="",ln="";
while((line=br.readLine())!=null){
ln+=line+"\n";
}