zoukankan      html  css  js  c++  java
  • File 参数 模拟POST请求

        public String OperationOrderSend(Map<String,String> params,String apiMethodName)
            throws IOException {
                Map<String,String> textParams=new HashMap<String,String>(params); //文本请求参数 
                Map<String,String> fileParams=new HashMap<String,String>(); //文件请求参数
                if(apiMethodName.equals("sendGoods")){
                    fileParams.put("sendGoods",params.get("sendGoods"));
                    textParams.remove("sendGoods");
                }
                textParams.put("gShopID", shopId);
                String validate = getValidateString(apiMethodName, textParams, apiKey);
                System.out.println("是这个验证码么:"+validate);
                
                String targetURL = "http://api.dangdang.com/v2/sendGoods.php"; // servleturl
                HttpClient httpClient = new HttpClient();
                PostMethod postMethod = new PostMethod(targetURL);
                
                
                
                String temp = null;
                temp = ServletActionContext.getServletContext().getRealPath("");
                temp = temp+"//temp//temp.xml";
                
                File file = new File(temp);
                Part [] parts = new Part[3];
                parts[0] = new StringPart("gShopID",shopId);
                try {
                    parts[1] = new FilePart("sendGoods", file,"text/xml","GBK");
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }//第三个参数就是说明这个文件类型是xml的,不用这个的话,接口会返回说上传的文件不是xml类型
                parts[2] = new StringPart("validateString",getValidateString(apiMethodName, textParams, apiKey)); 
                postMethod.setRequestEntity(new    MultipartRequestEntity(parts,postMethod.getParams())); 
                int statusCode = httpClient.executeMethod(postMethod);
                System.out.println("反馈信息为:"+new String(postMethod.getResponseBody()));;
                String info = new String(postMethod.getResponseBody());
                postMethod.releaseConnection();
                return info;
        }
  • 相关阅读:
    Jmeter命令行运行实例讲解
    ab压力测试工具
    F12找到页面某一元素所绑定的点击事件
    F12修改html进行本地js操作页面元素
    JMeter中利用Parameters 和Body Data传递参数有什么不同
    centos7 VNC安装
    centos7安装python3
    linux du命令的疑惑
    centos cgroup配置
    linux下postgres未能正常启动的解决过程
  • 原文地址:https://www.cnblogs.com/jayGold/p/3325915.html
Copyright © 2011-2022 走看看