java - 带有正文 x-www-urlencode 授权类型、用户、密码的 Java Post 请求
问题描述
你好我试图做这样的请求:
public Object getToken() throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://URL_SERVEUR_AUTH.com");
httpPost.setHeader("Content-Type","application/x-www-form-urlencoded");
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("grant_type", "client_credentials"));
params.add(new BasicNameValuePair("user", "USER"));
params.add(new BasicNameValuePair("password", "PASSWORD"));
httpPost.setEntity(new UrlEncodedFormEntity(params));
System.out.println(httpPost);
CloseableHttpResponse response = client.execute(httpPost);
client.close();
return response;
}
看答案:
HttpResponseProxy{HTTP/1.1 500 ERROR [Date: Mon, 08 Oct 2018 09:30:05 GMT,
Connection: close,
Host: http://URL_SERVEUR_AUTH.com,
Content-Type: text/html; charset="utf-8",
Set-Cookie: TS****=***********************************; Path=/,
Transfer-Encoding: chunked] ResponseEntityProxy{[Content-Type: text/html;
charset="utf-8",Chunked: true]}}
解决方案
推荐阅读
- javascript - CallBackUrl 页面上的会话 id 不断变化
- meshlab - 如何测量两个 3D STL 模型之间的豪斯多夫距离
- go - 为什么我在 Go 中遇到分段违规错误
- express - 如何防止所有工作线程执行 cron 作业
- python - 任何人都知道一个简单的方法来编码这个问题?
- php - 有没有办法在 php 中通过引用传递临时数组?
- php - 防止 Laravel Mongo 数据库中的数据覆盖
- google-bigquery - BigQuery 相当于 SELECT * FROM (VALUES ...) AS t
- flutter - Flutter 错误 - 没有为该类型定义方法“setState”
- angular - Angular - 浏览器无法识别新类,将它们视为“未定义”