您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

NameValuePair方式传参数实例教程

2024/3/25 9:40:10发布20次查看
今天工作中联调外部的一个接口用post方式传输,我按照文档封装参数成jason字符串传入,但是对方一直接受参数为空,折腾了半天也没找到问题。很苦恼,检查代码都没有错误,可是为什么对方接受参数为空呢?然后找对方的技术人员联调,看看是怎么回事,也折腾了半天最后发现对方是用namevaluepair方式传参数。虽然这个方式已经过时了,但是在这里记录下,以备以后出现类似的方式传参数。
1 /** 2 /** 3 * 定义了一个list,该list的数据类型是namevaluepair(简单名称值对节点类型), 4 * 这个代码用于java像url发送post请求。在发送post请求时用该list来存放参数。 5 */ 6 7 list<namevaluepair> urlparameters = new arraylist<>(); 8 urlparameters.add(new basicnamevaluepair("token", token)); 9 urlparameters.add(new basicnamevaluepair("city", city)); 10 urlparameters.add(new basicnamevaluepair("timestamp", timestamp)); 11 urlparameters.add(new basicnamevaluepair("sign", sign)); 12 ... 13 14 httppost post = new httppost("http://****:8047/v4.0/quoted");//建立httppost对象 15 post.setentity(new urlencodedformentity(urlparameters, http.utf_8));//设置编码 16 httpresponse response=new defaulthttpclient().execute(post);//发送post,并返回一个httpresponse对象 17 string content = entityutils.tostring(response.getentity(), "utf-8");
以上就是namevaluepair方式传参数实例教程的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product