• httpclient_1


    用到的jar:commons-codec-1.6.jar、commons-httpclient-3.0.jar、commons-logging-1.1.3.jar

    package com.httpclient;

    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeMap;

    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.NameValuePair;
    import org.apache.commons.httpclient.methods.PostMethod;
    import org.apache.commons.httpclient.params.HttpMethodParams;

    public class TT {
        public static void main(String[] args) {
            TT dp = new TT();
            System.out.println(dp.getPack("1039", "1003"));
        }
        public String getPack(String grade,String subject) {
            TreeMap<String,String> map=new TreeMap<String,String>();
            map.put("commandid", "guestpacklist");
            map.put("grade", grade);
            map.put("subject", subject);
            NameValuePair[] data = new NameValuePair[addSigned(map).keySet().size()]; 
            Iterator it = map.entrySet().iterator(); 
            int i = 0; 
            while (it.hasNext()) { 
                Map.Entry entry = (Map.Entry) it.next(); 
                Object key = entry.getKey(); 
                Object value = entry.getValue(); 
                data[i] = new NameValuePair(key.toString(), value.toString()); 
                i++; 
            }
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod("http://api.xxx.hk/api/android/");
           post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"UTF-8");
            post.setRequestBody(data);
            try {
                client.executeMethod(post);
              return post.getResponseBodyAsString();
               
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
               post.releaseConnection();
            }
            return "nothing response!maybe can`t connect to the host!";
        }

        public static TreeMap<String, String> addSigned(
                TreeMap<String, String> parmas) {
            // 前面参数(TreeMap),组合后再拼上key,最后一起加密为signed参数。最后返回之前的参数和signed

           String signed = "";
            Set<String> key = parmas.keySet();
            for (Iterator it = key.iterator(); it.hasNext();) {
                String s = (String) it.next();
                // P.systemOut(s + " -> ");
                // P.systemOut(parmas.get(s));
                signed += s + parmas.get(s);
            }
            signed += "abcde123abcde123abcde123abcde123a";
            parmas.put("signed", JT_MD5.encodeString(signed.getBytes()));

            return parmas;
        }
    }

  • 相关阅读:
    文件可视化的脚本
    Qt error: invalid application of 'sizeof' to incomplete type 'QStaticAssertFailure<false>'
    libusb(4)在Qt中使用libusb
    USB开发者培训(2)架构、系统、协议和供电
    USB开发者培训(1)技术背景
    你的py文件转换成linux可执行程序
    UOS在启动KVM虚拟机时,发生了如下错误
    远程文件到本地
    linux系统后台运行python脚本
    IEEE Journals, Conferences and Their Abbreviation
  • 原文地址:https://www.cnblogs.com/stay-sober/p/4169698.html
Copyright © 2020-2023  润新知