0

我正在尝试使用 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";
}
4

1 回答 1

1

表单标签有一个独特的组件,每次登录尝试都会改变:

<form action="./ucp.php?mode=login&amp;sid=a1867e90f9f131fb99676a9db3892c95" method="post">

我不知道您还需要做什么,但至少,我希望您需要在尝试发布凭据之前加载登录页面并解析该操作 URL。另外,请注意,一些管理员不喜欢连接到供人类使用的站点的自动化系统。

于 2012-06-09T22:50:18.803 回答