NutzCN Logo
问答 HttpPost BasicNameValuePair 参数设置问题
发布于 2703天前 作者 sniperZj 8623 次浏览 复制 上一个帖子 下一个帖子
标签:

//用HttpPost方式post参数时,我用了BasicNameValuePair类添加参数,但是BasicNameValuePair类的参数(key/value)只支持String格式,如果想传递int参数该 咋整 没百度到
public String tgest(String mobile,int id){
String url = "https://test.action";
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
addHeader(httpPost);
String status ="-1";
try {
// 设置请求的参数
List nvps = new ArrayList();
nvps.add(new BasicNameValuePair("id", id)); //第三方接口 要求请求 参数 id 为int 类型 此时 id只能穿 字符串 改怎么传 int类型的参数
nvps.add(new BasicNameValuePair("mobile", mobile));

       HttpResponse response = httpClient.execute(httpPost);
       JSONObject jsonobject = JSON.parseObject(EntityUtils.toString(response.getEntity(), "utf-8"));
       System.out.println(jsonobject.getString("code"));
       if("200".equals(jsonobject.getString("code"))){
         return jsonobject.getString("obj");
       }else{
         return status;
       }
    } catch (Exception e) {
       e.printStackTrace();
       return status;
    }

}

1 回复

http参数只有字符串, int转String啊

添加回复
请先登陆
回到顶部