cnzz 類比請求登入(傳入url get data ) demo

來源:互聯網
上載者:User

標籤:儲存   cnzz   ace   pass   eal   string   類比   generated   sel   

/** *  * @Title: init * @Description: TODO 初始化httpclien * @param url *            cnzz對應的連結 * @param password *            cnzz 對應的密碼 * @return *  * @return: HttpClient */public static String init(HttpClient httpclient, String url, String password) {// 建立 httpPost對象HttpPost httpPost = new HttpPost(url);// 建立一個NameValuePair數組,用於儲存欲傳送的參數List<NameValuePair> params = new ArrayList<NameValuePair>();params.add(new BasicNameValuePair("password", password));String locationUrl = "";try {// 設定為utf-8編碼httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));HttpResponse response = httpclient.execute(httpPost);// 擷取 重新導向後的urllocationUrl = response.getLastHeader("Location").getValue();// 設定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() + "-----");}}// 獲得返回體HttpEntity entity = response.getEntity();// 獲得體內容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 根據登陸後跳轉的連結發送 第二次請求 * @param httpclient * @param locationUrl *            登陸後重新導向的連結 *  * @return: url */public static String sendTwoRequest(HttpClient httpclient, String locationUrl) {String url = "";try {// 發送get請求HttpGet httpGet = new HttpGet(locationUrl);HttpResponse response = httpclient.execute(httpGet);HttpEntity entity = response.getEntity();String responseHtmQueryPage = IOUtils.toString(entity.getContent());Document 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 發送第三次請求 * @param httpclient * @param url * @return *  *  */public static void sendThreeRequest(HttpClient httpclient, String url) {try {// 發送get請求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 發送第四次請求 及要擷取的真正資料的請求 * @param httpclient * @param realUrl * @return *  * @return: String */public static String sendFourRequest(HttpClient httpclient, String realUrl) {// 發送get請求String responseHtmQueryPage = "";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 類比請求登入(傳入url get data ) demo

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.