我正在尝试使用java和eclipse登录使用Http apache客户端的站点。我已经尝试了很多编写代码的方法,但它仍然不起作用:
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";
}
答案 0 :(得分:1)
表单标记有一个唯一的组件,可以更改每次登录尝试:
<form action="./ucp.php?mode=login&sid=a1867e90f9f131fb99676a9db3892c95" method="post">
我不知道您可能需要做什么,但至少,我希望您在尝试发布凭据之前,需要加载登录页面并解析该操作URL。此外,请注意,某些管理员并不善待连接到人类网站的自动化系统。