接口中数据流的格式发送请求和解析流请求

10 篇文章 0 订阅

数据流格式发送请求:

HttpClient hc = new HttpClient();

            int httpcode = 0;
            hc.setConnectionTimeout(10000);
            hc.setTimeout(8000);
            PostMethod pm = new PostMethod(supplierServerUrl);
            String sign = util.MD5HEX(AgentID+Timestamp+AgentOrderID+GoodsTypeID+GoodsID+PayNumber+Amount+key);
            String source="{\"header\": {\"AgentID\":\""+AgentID+"\",\"Timestamp\":\""+Timestamp+"\",\"sign\":\""+sign+"\"},\"body\": {\"AgentOrderID\": \""+AgentOrderID+"\",\"GoodsTypeID\": \""+GoodsTypeID+"\",\"GoodsID\": \""+GoodsID+"\",\"PayNumber\": \""+PayNumber+"\",\"Amount\": \""+Amount+"\"}}";
            System.out.println(source);
            RequestEntity se = new StringRequestEntity(source,
                    "application/x-www-form-urlencoded","utf-8");
            pm.setRequestEntity(se);
            httpcode = hc.executeMethod(pm);
            responseStr=pm.getResponseBodyAsString();

            pm.releaseConnection();




解析流格式:

int httpcode = 0;
String resposeStr = "";
HttpClient hc = new HttpClient();
hc.setConnectionTimeout(15000);
hc.setTimeout(15000);
PostMethod pm = new PostMethod(supplierServerUrl);
pm.setRequestBody(nvp);
httpcode = hc.executeMethod(pm);
InputStream is = pm.getResponseBodyAsStream(); 
            BufferedReader br=new BufferedReader(new InputStreamReader(is,"utf-8")); 
            String line=null; 
            char[] c=new char[1024]; 
            int len=0; 
            while(-1 != (len = br.read(c))){ 
            line=new String(c, 0, len); 
            }
            responseStr=line;
pm.releaseConnection();
is.close();
br.close();




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值