Log in with HttpClient Post

I am trying to create a program that registers on a site and performs some automated actions. I am using HttpClient 4.0.1 and using this to start: http://hc.apache.org/httpcomponents-client/primer.html .

On this particular site, cookies are not set via the "set-cookie" header, but in javascript.

So far, I have not been able to sign in.

I have tried the following things:

  • manually add headers for all request headers that appear in firebug
   NameValuePair [] data = {
         new BasicNameValuePair ("Host", host),
         new BasicNameValuePair ("User-Agent", "Mozilla / 5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: 1.9.1.7) Gecko / 20091221 Firefox / 3.5.7"),
         new BasicNameValuePair ("Accept", "text / html, application / xhtml + xml, application / xml; q = 0.9, * / *; q = 0.8"),
         new BasicNameValuePair ("Accept-Language", "en-us, en; q = 0.5"),
         new BasicNameValuePair ("Accept-Encoding", "gzip, deflate"),
         new BasicNameValuePair ("Accept-Charset", "ISO-8859-1, utf-8; q = 0.7, *; q = 0.7"),
         new BasicNameValuePair ("Keep-Alive", "300"),
         new BasicNameValuePair ("Connection", "keep-alive"),
         new BasicNameValuePair ("Referer", referer),
         new BasicNameValuePair ("Cookie", cookiestr)
   };

   for (NameValuePair pair: data) {
      loginPost.addHeader (pair.getName (), pair.getValue ());
   }

  1. BasicClientCookies setCookieStore. , , , cookie . , , ? (, ..).

, : HTTP/1.1 417

, - , ? , , .

+3
4

WireShark Fiddler. - ( , ); - , .

, , , , , .

+1

- Wireshark, , . Wireshark. Essential.

, http://hc.apache.org/httpcomponents-client/examples.html, " ".

Http BasicNameValuePair, HttpClient . HttpParams HttpConnectionParams/HttpProtocolParams. conn/ManagerConnectDirect , .

+1

"net" FireBug, , , . , , cookie ( , ). , cookie HttpClient :

method.setRequestHeader("Cookie", "special-cookie=value");
0
0

Source: https://habr.com/ru/post/1728424/


All Articles