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

The form tag has a unique component that changes every login attempt:

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

I don't know what else you may have to do, but at a minimum, I expect you need to load the login page and parse that action URL before attempting to post the credentials. Also, be aware that some administrators don't take kindly to automated systems connecting to sites intended for humans.

于 2012-06-09T22:50:18.803 に答える