首 页 行业热点 新车 试驾评测 养车用车 车型库

java调用rest接口如何HttpClient 使用put x-www-form-urlencoded数据?

发布网友 发布时间:2022-04-22 15:17

我来回答

1个回答

热心网友 时间:2023-11-10 08:21

把post的改成put试试
HttpPost httpPost = new HttpPost("http xxx");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username", "vip"));
nvps.add(new BasicNameValuePair("password", "secret"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
CloseableHttpResponse response2 = httpclient.execute(httpPost);

try {
System.out.println(response2.getStatusLine());
HttpEntity entity2 = response2.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
EntityUtils.consume(entity2);
} finally {
response2.close();
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com