具有主体x-www-urlencode授予类型,用户,密码的Java Post请求

时间:2018-10-08 09:58:56

标签: java http 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]}}

0 个答案:

没有答案