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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java调用rest接口如何HttpClient 使用put x-www-form-urlencoded数据?相关的知识,希望对你有一定的参考价值。

java后台调用rest put请求为此类型的数据格式 用httpClient方式怎么请求,求赐教

参考技术A 把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();
本回答被提问者采纳

以上是关于java调用rest接口如何HttpClient 使用put x-www-form-urlencoded数据?的主要内容,如果未能解决你的问题,请参考以下文章

实现Restful接口

这种接口怎么调用?怎么传递参数?

java 通过httpclient调用https 的webapi

httpclient在并发量较高的调用下问题如何去

使用HttpClient访问接口(Rest接口和普通接口)

java调用webservice接口具体怎么调用