国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - java實現京東登陸示例分享

java實現京東登陸示例分享

2019-11-12 14:21java教程網 JAVA教程

這篇文章主要介紹了使用java實現的京東商城登陸示例,需要的朋友可以參考下

代碼如下:

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();
    }
}

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 少妇久久久 | 91中文字幕在线观看 | 超碰c | 日本不卡高字幕在线2019 | 久久久久久久久久久久久国产 | 欧美日韩久久久 | 久久久久久亚洲精品 | 三级黄色片在线免费观看 | 亚洲一级淫片 | 高清久久 | 一区二区视频 | 午夜资源| 有码一区 | 精品久久久久久久久久久久久久 | 欧美精品欧美精品系列 | 综合久久精品 | 亚洲一区在线视频 | 毛片真人毛毛片毛片 | 国产欧美综合视频 | 亚洲精品成人在线 | 精品视频第一页 | 九九九色| 欧美日韩中文字幕在线 | 国产日韩精品久久 | 欧美高潮| 国产综合在线视频 | 国产成人综合在线观看 | 亚洲精品乱码久久久久久按摩观 | 欧美成人一级 | 久久久99精品免费观看 | 激情综合五月天 | 久久国产精品99久久久久久老狼 | 黄色毛片三级 | 久艹精品 | 亚洲精品久久久一区二区三区 | 日韩欧美专区 | 久久亚洲一区二区三区四区 | 国产专区一区二区三区 | 亚洲国产精品久久久久婷婷老年 | 国产女人爽到高潮免费视频 | 综合伊人久久 |