//用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;
}
}