HttpClient Simulation Landing Concrete Implementation

Source: Internet
Author: User

  The easiest way to do this is to customize a httpclient by getting cookies, and interested friends can understand this article

HttpClient Analog Login (use JS to set cookies)   code as follows: <html>  <meta http-equiv= ' content-type ' content= ' text/html; charset=gb2312 ' >  <link rel=stylesheet type=text/css href= '/bbs.css ' >  <script> Document.cookie= ' utmpnum=51;path=/;d omain=. ' +</script>  <script> Document.cookie= ' utmpkey=20154732;path=/;d omain=. ' +</script>  <script> Document.cookie= ' utmpuserid=yay;path=/;d omain=. ' +</script>  <meta http-equiv= ' Refresh ' content= ' 0; url=/firstpage.php ' >    h4ttpclient 4.3:    The easiest way to do this is to customize a httpclient by getting the cookie, based on the example above, the following method:     Code as follows: Cookiestore Cookiestore = new Basiccookiestore ();    for (int i = 0; i < 3; i++) {  S Tring name;  String value;  int flag=s.indexof ("Document.cookie");  s=s.substring (flag+17);  flag =s.indexof (' = ');  name=s.substring (0, flag);  value=s.substring (flag+1, S.indexof (';'));   Basicclientcookie cookie = new Basicclientcookie (name,  value);  cookie.setversion (0);  Cookie.setdomain ("."); This URL corresponds to <span style= "font-family:arial, Helvetica, Sans-serif;" > return value </span>  cookie.setpath ("/");  Cookiestore.addcookie (cookie); }  //Set the store  closeablehttpclient httpclient = Httpclients.custom ()  . Setdefaultcookiestore ( Cookiestore)   Build ();    android:    I've been looking for it for half a day. The corresponding API for the above method can only be added with a cookie before each visit   code is as follows: String Cookie= "";  for (int i = 0; i < 3; i++) {  string name;  string value;  int Flag=s.indexof (" Document.cookie ");  s=s.substring (flag+17);  flag=s.indexof (' = ');  name=s.substring (0, flag);  Value=s.substring (flag+1, S.indexof (';'));   Cookie +=name + "=" +value;  if (i!=2)   cookie+= ";";  }   /*  * Every access network   */  httpget httpget = new HttpgeT (URL);  httpget.addheader ("cookie", cookie); //If there is already a cookie in httpclient, you may need to set a httpclient cookie policy. Specific official API (:  HttpResponse response = Httpclient.execute (httpget);     
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.