亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

java實(shí)現(xiàn)京東登陸示例分享

 更新時(shí)間:2014年03月02日 09:32:15   作者:  
這篇文章主要介紹了使用java實(shí)現(xiàn)的京東商城登陸示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

package com.lkb.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.BufferedHeader;
import org.apache.http.protocol.HTTP;

import com.util.Constant;

public class JD {
    // The configuration items

   
    private static String redirectURL = "http://order.jd.com/center/list.action";
    private static String loginUrl = "http://passport.jd.com/uc/login";
    // Don't change the following URL
    private static String renRenLoginURL = "https://passport.jd.com/uc/loginService";

    // The HttpClient is used in one session
    private HttpResponse response;
    private DefaultHttpClient httpclient = new DefaultHttpClient();

    public  Map<String,String> getParams(){
     Map<String,String> map = new HashMap<String,String>();
     String str = getText(loginUrl);
     String strs1[] = str.split("name=\"uuid\" value=\"");
     String strs2[] = strs1[1].split("\"/>");
     String uuid = strs2[0];
     map.put("uuid", uuid);
     System.out.println(strs2[0]);
     String str3s[] = strs1[1].split("<span class=\"clr\"></span><input type=\"hidden\" name=\"");
     String strs4[] = str3s[1].split("/>");
     String strs5[] = strs4[0].trim().split("\"");
     String key = strs5[0];
     String value = strs5[2];
     map.put(key, value);
     return map;
    }
    private boolean login() {
     Map map = getParams();

        HttpPost httpost = new HttpPost(renRenLoginURL);
        // All the parameters post to the web site
        List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
        nvps.add(new BasicNameValuePair("ReturnUrl", redirectURL));
        nvps.add(new BasicNameValuePair("loginname", Constant.userName));
        nvps.add(new BasicNameValuePair("nloginpwd", Constant.password));
        nvps.add(new BasicNameValuePair("loginpwd", Constant.password));
        Iterator it = map.keySet().iterator();
        while(it.hasNext()) {
         String key = it.next().toString();
         String value = map.get(key).toString();
         nvps.add(new BasicNameValuePair(key, value));

        }

        try {
            httpost.setEntity(new UrlEncodedFormEntity((List<? extends org.apache.http.NameValuePair>) nvps, HTTP.UTF_8));
            response = httpclient.execute(httpost);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            httpost.abort();
        }
        return true;
    }

    private String getRedirectLocation() {
     BufferedHeader locationHeader =  (BufferedHeader) response.getFirstHeader("Location");
        if (locationHeader == null) {
            return null;
        }
        return locationHeader.getValue();
    }

    private String getText(String redirectLocation) {
        HttpGet httpget = new HttpGet(redirectLocation);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = "";
        try {
            responseBody = httpclient.execute(httpget, responseHandler);
        } catch (Exception e) {
            e.printStackTrace();
            responseBody = null;
        } finally {
            httpget.abort();
            //httpclient.getConnectionManager().shutdown();
        }
        return responseBody;
    }

    public void printText() {
        if (login()) {        
         System.out.println(getText(redirectURL));
           String redirectLocation = getRedirectLocation();
            if (redirectLocation != null) {
                System.out.println(getText(redirectLocation));
            }
        }
    }

    public static void main(String[] args) {
          JD renRen = new JD();
          //renRen.getParams();
          renRen.printText();
    }
}

相關(guān)文章

  • mybatisplus如何在xml的連表查詢中使用queryWrapper

    mybatisplus如何在xml的連表查詢中使用queryWrapper

    這篇文章主要介紹了mybatisplus如何在xml的連表查詢中使用queryWrapper,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • SpringBoot 創(chuàng)建web項(xiàng)目并部署到外部Tomcat

    SpringBoot 創(chuàng)建web項(xiàng)目并部署到外部Tomcat

    本篇文章主要介紹了SpringBoot 創(chuàng)建web項(xiàng)目并部署到外部Tomcat,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • Springmvc中的轉(zhuǎn)發(fā)重定向和攔截器的示例

    Springmvc中的轉(zhuǎn)發(fā)重定向和攔截器的示例

    本篇文章主要介紹了Springmvc中的轉(zhuǎn)發(fā)重定向和攔截器的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-05-05
  • 一小時(shí)迅速入門Mybatis之bind與多數(shù)據(jù)源支持 Java API

    一小時(shí)迅速入門Mybatis之bind與多數(shù)據(jù)源支持 Java API

    這篇文章主要介紹了一小時(shí)迅速入門Mybatis之bind與多數(shù)據(jù)源支持 Java API,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • idea使用Maven Helper插件去掉無用的poom 依賴信息(詳細(xì)步驟)

    idea使用Maven Helper插件去掉無用的poom 依賴信息(詳細(xì)步驟)

    這篇文章主要介紹了idea使用Maven Helper插件去掉無用的poom 依賴信息,本文分步驟給大家講解的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-04-04
  • Java文件快速copy復(fù)制實(shí)例代碼

    Java文件快速copy復(fù)制實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于Java文件快速copy復(fù)制的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • Java設(shè)計(jì)模式之單一職責(zé)原則精解

    Java設(shè)計(jì)模式之單一職責(zé)原則精解

    設(shè)計(jì)模式(Design pattern)代表了最佳的實(shí)踐,通常被有經(jīng)驗(yàn)的面向?qū)ο蟮能浖_發(fā)人員所采用。設(shè)計(jì)模式是軟件開發(fā)人員在軟件開發(fā)過程中面臨的一般問題的解決方案。本篇介紹設(shè)計(jì)模式七大原則之一的單一職責(zé)原則
    2022-02-02
  • 分析Springboot中嵌套事務(wù)失效原因詳解

    分析Springboot中嵌套事務(wù)失效原因詳解

    這篇文章主要為大家介紹了分析Springboot中嵌套事務(wù)失效原因詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2021-11-11
  • 淺談SpringBoot集成Quartz動(dòng)態(tài)定時(shí)任務(wù)

    淺談SpringBoot集成Quartz動(dòng)態(tài)定時(shí)任務(wù)

    這篇文章主要介紹了SpringBoot集成Quartz動(dòng)態(tài)定時(shí)任務(wù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Apache?Commons?Imaging處理圖像實(shí)例深究

    Apache?Commons?Imaging處理圖像實(shí)例深究

    這篇文章主要為大家介紹了Apache?Commons?Imaging處理圖像的實(shí)例探索深究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12

最新評論