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方式传参数实例教程的详细内容。
