Example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair

List of usage examples for org.apache.http.message BasicNameValuePair BasicNameValuePair

Introduction

In this page you can find the example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair.

Prototype

public BasicNameValuePair(String str, String str2) 

Source Link

Usage

From source file:com.lsq.httpclient.netpay.BasicInfo.java

public static void main(String[] args) throws Exception {
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("F://test/pkcs8_rsa_private_key_2048.pem", "pem", null, "RSA");
    //   final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("F://??/rsa_public_key_2048.pem", "pem", "RSA");
    ///*from  w  w  w  .  j  a  v  a 2  s .  c o  m*/
    //   final String url = "http://localhost:8080/interfaceWeb/basicInfo";
    //   final String url = "https://testapp.sicpay.com:11008/interfaceWeb/basicInfo";   

    //?
    //   final String url = "http://120.31.132.120:8082/interfaceWeb/basicInfo";
    //       final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("C:\\document\\key\\000158120120\\GHT_ROOT.pem", "pem", "RSA");
    //        final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:\\document\\key\\000000153990021\\000000153990021.pem", "pem", null, "RSA");
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:/document/key/000000158120121/000000158120121.pem", "pem", null, "RSA");
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("D:/key/000000152110003.pem", "pem", null, "RSA");
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("D:/key/test_pkcs8_rsa_private_key_2048.pem", "pem", null, "RSA");
    //   PublicKey yhPubKey = TestUtil.getPublicKey();
    //   PrivateKey hzfPriKey = TestUtil.getPrivateKey();

    //    final String url = "http://epay.gaohuitong.com:8083/interfaceWeb/basicInfo";

    //        final String url = "http://gpay.gaohuitong.com:8086/interfaceWeb2/basicInfo";
    //       final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("C:/document/key/549440155510001/GHT_ROOT.pem", "pem", "RSA");
    //    final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:/document/key/549440155510001/549440155510001.pem", "pem", null, "RSA");

    //    final String url = "https://portal.sicpay.com:8087/interfaceWeb/basicInfo";

    final String url = TestUtil.interface_url + "basicInfo";

    final PublicKey yhPubKey = TestUtil.getPublicKey();
    final PrivateKey hzfPriKey = TestUtil.getPrivateKey();

    int i = 0;
    //   int j = 0;
    while (i < 1) {
        i++;
        try {
            HttpClient4Util httpClient4Util = new HttpClient4Util();
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sBuilder.append("<merchant>");
            sBuilder.append("<head>");
            sBuilder.append("<version>2.0.0</version>");
            //         sBuilder.append("<agencyId>549440155510001</agencyId>");
            sBuilder.append("<agencyId>" + TestUtil.merchantId + "</agencyId>");
            sBuilder.append("<msgType>01</msgType>");
            sBuilder.append("<tranCode>100001</tranCode>");
            sBuilder.append("<reqMsgId>" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + i + i
                    + "</reqMsgId>");
            sBuilder.append("<reqDate>" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "</reqDate>");
            sBuilder.append("</head>");
            sBuilder.append("<body>");

            sBuilder.append("<handleType>0</handleType>");
            sBuilder.append("<merchantName>LIBTEST1</merchantName>");
            sBuilder.append("<shortName>UNCLE HENRY(A)</shortName>");
            sBuilder.append("<city>344344</city>");
            sBuilder.append(
                    "<merchantAddress>UNIT C 15/FHUA CHIAO COMM CTR 678 NATHAN RD MONGKOK KL</merchantAddress>");
            sBuilder.append("<servicePhone>13250538964</servicePhone>");
            sBuilder.append("<orgCode></orgCode>");
            sBuilder.append("<merchantType>01</merchantType>");
            sBuilder.append("<category>5399</category>");
            sBuilder.append("<corpmanName>?</corpmanName>");
            sBuilder.append("<corpmanId>440103198112214218</corpmanId>");
            sBuilder.append("<corpmanPhone>13926015921</corpmanPhone>");
            sBuilder.append("<corpmanMobile>13926015921</corpmanMobile>");
            sBuilder.append("<corpmanEmail>>zhanglibo@sicpay.com</corpmanEmail>");
            sBuilder.append("<bankCode>105</bankCode>");
            sBuilder.append("<bankName></bankName>");
            sBuilder.append("<bankaccountNo>6250502002603958</bankaccountNo>");
            sBuilder.append("<bankaccountName>?</bankaccountName>");
            sBuilder.append("<autoCus>0</autoCus>");
            sBuilder.append("<remark></remark>");
            sBuilder.append("<licenseNo>91440184355798892G</licenseNo>");
            //         sBuilder.append("<taxRegisterNo></taxRegisterNo>");
            //         sBuilder.append("<subMerchantNo></subMerchantNo>");
            //         sBuilder.append("<inviteMerNo></inviteMerNo>");
            //         sBuilder.append("<county></county>");
            //         sBuilder.append("<appid>wx04df48e919ef7b28</appid>");
            //         sBuilder.append("<pid>2015062600009243</pid>");
            //         sBuilder.append("<childEnter>1</childEnter>");
            //         sBuilder.append("<ghtEnter>0</ghtEnter>");
            //         sBuilder.append("<addrType>BUSINESS_ADDRESS</addrType>");
            //         sBuilder.append("<contactType>LEGAL_PERSON</contactType>");
            //         sBuilder.append("<mcc>200101110640354</mcc>");
            //         sBuilder.append("<licenseType>NATIONAL_LEGAL_MERGE</licenseType>");
            //         sBuilder.append("<authPayDir>http://epay.gaohuitong.com/channel/|http://test.pengjv.com/channel/</authPayDir>");
            //         sBuilder.append("<scribeAppid>wx04df48e919ef7b28</scribeAppid>");
            //         sBuilder.append("<contactMan></contactMan>");
            //         sBuilder.append("<telNo>18675857506</telNo>");
            //         sBuilder.append("<mobilePhone>18675857506</mobilePhone>");
            //         sBuilder.append("<email>CSC@sicpay.com</email>");
            //         sBuilder.append("<licenseBeginDate>20150826</licenseBeginDate>");
            //         sBuilder.append("<licenseEndDate>20991231</licenseEndDate>");
            //         sBuilder.append("<licenseRange>?????????????</licenseRange>");

            sBuilder.append("</body>");
            sBuilder.append("</merchant>");

            String plainXML = sBuilder.toString();
            byte[] plainBytes = plainXML.getBytes("UTF-8");
            String keyStr = "4D22R4846VFJ8HH4";
            byte[] keyBytes = keyStr.getBytes("UTF-8");
            byte[] base64EncryptDataBytes = Base64.encodeBase64(
                    CryptoUtil.AESEncrypt(plainBytes, keyBytes, "AES", "AES/ECB/PKCS5Padding", null));
            String encryptData = new String(base64EncryptDataBytes, "UTF-8");
            byte[] base64SingDataBytes = Base64
                    .encodeBase64(CryptoUtil.digitalSign(plainBytes, hzfPriKey, "SHA1WithRSA"));
            String signData = new String(base64SingDataBytes, "UTF-8");
            byte[] base64EncyrptKeyBytes = Base64
                    .encodeBase64(CryptoUtil.RSAEncrypt(keyBytes, yhPubKey, 2048, 11, "RSA/ECB/PKCS1Padding"));
            String encrtptKey = new String(base64EncyrptKeyBytes, "UTF-8");
            List<NameValuePair> nvps = new LinkedList<NameValuePair>();
            nvps.add(new BasicNameValuePair("encryptData", encryptData));
            nvps.add(new BasicNameValuePair("encryptKey", encrtptKey));
            //         nvps.add(new BasicNameValuePair("agencyId", "549440155510001"));
            nvps.add(new BasicNameValuePair("agencyId", TestUtil.merchantId));
            nvps.add(new BasicNameValuePair("signData", signData));
            nvps.add(new BasicNameValuePair("tranCode", "100001"));
            //         nvps.add(new BasicNameValuePair("callBack","http://localhost:801/callback/ghtBindCard.do"));
            //          byte[] retBytes = httpClient4Util.doPost("http://localhost:8080/quickInter/channel/commonSyncInter.do", null, nvps, null);
            byte[] retBytes = httpClient4Util.doPost(url, null, nvps, null);
            //         byte[] retBytes =httpClient4Util.doPost("http://epay.gaohuitong.com:8082/quickInter/channel/commonSyncInter.do", null, nvps, null);
            //           byte[] retBytes = httpClient4Util.doPost("http://192.168.80.113:8080/quickInter/channel/commonSyncInter.do", null, nvps, null);

            String response = new String(retBytes, "UTF-8");
            System.out.println(" ||" + new String(retBytes, "UTF-8") + "||");
            TestEncype t = new TestEncype();
            System.out.println(": ||" + t.respDecryption(response) + "||");
            System.out.println("i" + i);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static List<NameValuePair> convertMap2List(Map<String, String> params) {
    if (params.isEmpty())
        return null;
    List<NameValuePair> paramList = new ArrayList<NameValuePair>();
    for (Map.Entry<String, String> entry : params.entrySet()) {
        paramList.add(new BasicNameValuePair(entry.getKey().trim(), entry.getValue().trim()));
    }/*from   www .  ja  v a 2s  .co  m*/
    return paramList;
}

From source file:Main.java

public static List<NameValuePair> convertParametersToNameValuePairs(final Map<String, String> pParameters) {
    final List<NameValuePair> result = new ArrayList<NameValuePair>();

    for (final Entry<String, String> entry : pParameters.entrySet()) {
        result.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }/*from  w w  w .  j  av a 2s .co m*/

    return result;
}

From source file:Main.java

public static void mergeParam(HashMap<String, Object> params, List<NameValuePair> valuePair) {
    if (params != null) {
        for (HashMap.Entry<String, Object> entry : params.entrySet()) {
            String key = entry.getKey();
            String value = String.valueOf(entry.getValue());
            valuePair.add(new BasicNameValuePair(key, value));
        }/* w  w  w  .ja v  a  2 s .c om*/
    }
}

From source file:Main.java

private static List<NameValuePair> buildNameValuePair(Hashtable<String, String> httpPost) {
    if (httpPost == null)
        return null;

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    Enumeration<String> keys = httpPost.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = (String) httpPost.get(key);
        BasicNameValuePair nv = new BasicNameValuePair(key, value);
        nvps.add(nv);//  w  ww .java  2 s .  c  o  m
    }

    return nvps;
}

From source file:Main.java

public static List<NameValuePair> convertParams(ContentValues params) {
    if (params == null || params.size() == 0)
        return null;

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    Set<Entry<String, Object>> setEntry = params.valueSet();
    BasicNameValuePair bnvp = null;//w  w w  .  j a v a2s  .  co  m

    for (Entry<String, Object> entry : setEntry) {
        bnvp = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
        nameValuePairs.add(bnvp);
    }

    return nameValuePairs;
}

From source file:Main.java

public static String openGetConnection(String urlString, Map<String, String> map) {
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (String key : map.keySet()) {
        nameValuePairs.add(new BasicNameValuePair(key, map.get(key)));
    }//from  w w  w  .  ja va2 s  .c  o  m
    String params = URLEncodedUtils.format(nameValuePairs, "utf-8");
    urlString += "?";
    urlString += params;
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(urlString);
    try {
        HttpResponse httpResponse = client.execute(get);
        BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
        StringBuilder json = new StringBuilder("");
        String line = null;
        while ((line = br.readLine()) != null) {
            json.append(line);
        }
        return json.toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:pingdesktop.Model.Auth.java

public static String Login(String username, String password) throws IOException, ParseException, JSONException {
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("username", username));
    nvps.add(new BasicNameValuePair("password", password));
    String response = HttpHandler.doPost(nvps, "user/login");

    //mapping json to object
    JSONObject json = (JSONObject) new JSONParser().parse(response);

    if (json.get("status") == "1") {
        String query_string[] = null;
        query_string[0] = "1";
        System.out.println(query_string[0]);
        query_string[1] = "2";
        System.out.println(query_string[1]);

        //query_string[0] = "sapi terbang";
        //SQLliteExecutor.SqlExecuteVoid(query_string);
    } else if (json.get("status") == "0") {
        response = json.get("error").toString();
    }//from  w ww  .  j a  va  2s . c o  m

    System.out.println(response);
    return response;
}

From source file:Main.java

public static String getRepsonseString(String url, Map<String, String> params) {
    HttpPost request = new HttpPost(url);
    List<NameValuePair> p = new ArrayList<NameValuePair>();
    for (String key : params.keySet()) {
        p.add(new BasicNameValuePair(key, params.get(key)));
    }/*from w  ww .j  a  v  a  2s  .c  om*/
    HttpClient httpClient = new DefaultHttpClient();
    String result = null;

    try {
        request.setEntity(new UrlEncodedFormEntity(p, HTTP.UTF_8));
        HttpResponse response = httpClient.execute(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            result = new String(EntityUtils.toString(response.getEntity()).getBytes("ISO_8859_1"), "UTF-8");
        }
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (httpClient != null)
            httpClient.getConnectionManager().shutdown();
    }
    return result;
}

From source file:net.reichholf.dreamdroid.helpers.enigma2.PowerState.java

public static ArrayList<NameValuePair> getStateParams(String state) {
    ArrayList<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("newstate", state));

    return params;
}