CNZZ Impersonation Request login (incoming URL get data) demo

Source: Internet
Author: User

/** * * @Title: Init * @Description: TODO initialize httpclien * @param URL * cnzz corresponding link * @param password * CNZZ corresponding Password * @return * * @return: HttpClient */public static string init (HttpClient HttpClient, string url, String PASSW ORD) {//Establish HttpPost object HttpPost httppost = new HttpPost (URL);//Create an Namevaluepair array to store the parameters to be transferred list<namevaluepair> params = new arraylist<namevaluepair> ();p Arams.add (New Basicnamevaluepair ("password", password)); String Locationurl = ""; try {//set to UTF-8 encoded httppost.setentity (new urlencodedformentity (params, HTTP. Utf_8)); HttpResponse response = Httpclient.execute (HttpPost);//Get redirected Urllocationurl = Response.getlastheader ("location"). GetValue ();//Set Cookielist<cookie> cookies = ((abstracthttpclient) httpclient). Getcookiestore (). GetCookies (); if (Cookies.isempty ()) {System.out.println ("None"),} else {for (int i = 0; i < cookies.size (); i++) {System.out.println (Cookies.get (i). GetName () + ":" + cookies.get (i). GetValue () + "-----");}} //Get return body httpentity entity = response.getentity ();//Get body content string responsehtmquerypage = Ioutils.tostring ( Entity.getcontent ());} catch (Clientprotocolexception e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//TODO Auto-generated catch Blocke.printstacktrace ();} return locationurl;}            /** * * @Title: SendRequest * @Description: TODO sends a second request based on the link to the login * @param httpclient * @param locationurl * Redirected links after Login * * @return: URL */public static string sendtworequest (HttpClient HttpClient, String locationurl) {string URL = ""; try {//Send GET request httpget HttpGet = new HttpGet (Locationurl); HttpResponse response = Httpclient.execute (HttpGet); httpentity entity = response.getentity (); String responsehtmquerypage = ioutils.tostring (Entity.getcontent ());D ocument Document = Jsoup.parse ( responsehtmquerypage); url = "https://web.umeng.com/" + document.select ("script"). html (). Split ("'") [1];} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} RetUrn URL;}  /** * * @Title: SendRequest * @Description: TODO sends a third request * @param httpclient * @param URL * @return * * */public static void Sendthreerequest (HttpClient HttpClient, String url) {try {//Send GET request httpget HttpGet = new HttpGet (URL); HttpResponse response = Httpclient.execute (HttpGet); httpentity entity = response.getentity (); String responsehtmquerypage = ioutils.tostring (Entity.getcontent ());} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} /** * * @Title: Sendfourrequest * @Description: TODO sends a request for the fourth time and the actual data to be obtained * @param httpclient * @param realurl * @return * * @return: string */public static string Sendfourrequest (HttpClient HttpClient, string realurl) {//Send GET request String RESPO Nsehtmquerypage = ""; try {httpget httpget = new HttpGet (Realurl); HttpResponse response = Httpclient.execute (HttpGet); httpentity entity = response.getentity (); responsehtmquerypage = Ioutils.tostring (Entity.getcontent ());} catch (Clientprotocolexception e) {//TODO Auto-generAted catch Blocke.printstacktrace ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} return responsehtmquerypage;}

  

CNZZ Impersonation Request login (incoming URL get data) demo

Related Article

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.