/** * * @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