Http post请求传输(application/x-www-form-urlencoded)

HttpUtil; 

    public static String postWithParamsForString(String url, List<NameValuePair> params){
        HttpClient client = HttpClients.createDefault();
        HttpPost httpPost =   new HttpPost(url);
        String msg = "";
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
            httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
            HttpResponse response = client.execute(httpPost);
            int statusCode = response.getStatusLine().getStatusCode();
            if(statusCode==200){
                HttpEntity entity = response.getEntity();
                msg = EntityUtils.toString(entity);
                System.out.println(msg);
//                String conStrValue=response.get
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return msg;
    }
        NameValuePair Pair1=new BasicNameValuePair("mertId",mertId);
        NameValuePair Pair2=new BasicNameValuePair("outNo",outNo);
        NameValuePair Pair3=new BasicNameValuePair("pId",pId);
        NameValuePair Pair4=new BasicNameValuePair("version","1.0");
        NameValuePair Pair5=new BasicNameValuePair("fname",fname);
        NameValuePair Pair6=new BasicNameValuePair("aType",aType);
        NameValuePair Pair7=new BasicNameValuePair("number","1");
        NameValuePair Pair8=new BasicNameValuePair("nfUrl","http://127.0.0.1/d22");
        NameValuePair Pair9=new BasicNameValuePair("timeStamp",""+date);
        NameValuePair Pair10=new BasicNameValuePair("sign",sign);
        pairList.add(Pair1);
        pairList.add(Pair2);
        pairList.add(Pair3);
        pairList.add(Pair4);
        pairList.add(Pair5);
        pairList.add(Pair6);
        pairList.add(Pair7);
        pairList.add(Pair8);
        pairList.add(Pair9);
        pairList.add(Pair10);

        String json= HttpUtils.postWithParamsForString(SEVER_URL,pairList);

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值