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";
}