当我尝试使用可关闭的http请求执行http请求时,遇到此内容长度标头已出现的错误
package com.dotcomculture.arbbot;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.CloseableHttpResponse;
public class ArbBot {
public static void main(String [ ] args)throws Exception{
System.out.println("I am in main" );
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://api.sandbox.gemini.com");
httpPost.setHeader("Content-type", "text/plain");
httpPost.setHeader("Content-Length", "0");
httpPost.setHeader("X-GEMINI-APIKEY", "API KEY HERE");
httpPost.setHeader("X-GEMINI-PAYLOAD", "Payload here");
httpPost.setHeader("X-GEMINI-SIGNATURE", "Signature here");
httpPost.setHeader("Cache-Control", "0");
CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost);
int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
System.out.println("Status Code : " +statusCode );
}
}
下面的POM.XML
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.9</version>
</dependency>
如何删除默认内容长度标题?有谁知道?