我从服务器收到了一个有效的令牌,现在我想用这个令牌发送一个 GET 请求。 我的代码:
//My site is set as insecure, so I set the following setting
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();
HttpGet request = new HttpGet("https://xxxxxxxxxxxxxxxxx");
request.addHeader("Authorization", "Bearer " + access_token);
CloseableHttpResponse response = httpClient.execute(request);
但我得到错误:
java.lang.IllegalArgumentException: method GET must not have a request body.
我是 HTTP 调用的新手, 我很乐意提供帮助和解决方案。