Content-Length header already present解决办法

妖狐艹你老母 2024-04-18 13:10 167阅读 0赞
  1. org.apache.http.client.ClientProtocolException
  2. at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
  3. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
  4. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
  5. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
  6. at com.sydney.dream.common.utils.HttpClientBean.executeGetLeGaun(HttpClientBean.java:337)
  7. at com.sydney.dream.common.demo.DemoLeguan.main(DemoLeguan.java:24)
  8. Caused by: org.apache.http.ProtocolException: Content-Length header already present
  9. at org.apache.http.protocol.RequestContent.process(RequestContent.java:97)
  10. at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)
  11. at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:183)
  12. at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
  13. at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
  14. at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
  15. ... 5 more
  16. null
  17. stoping to debug..
  18. Process finished with exit code 0

把httpPost 中的Content-Length 设置去掉

  1. httpPost.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36");
  2. httpPost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
  3. httpPost.setHeader("Accept-Encoding", "gzip, deflate, br");
  4. httpPost.setHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
  5. httpPost.setHeader("Connection", "keep-alive");
  6. // httpPost.setHeader("Content-Length", "551");

发表评论

表情:
评论列表 (有 0 条评论,167人围观)

还没有评论,来说两句吧...

相关阅读