gpt4 book ai didi

java - Apache HttpClient 收到 "406 Not Acceptable"错误

转载 作者:行者123 更新时间:2023-12-02 12:58:54 25 4
gpt4 key购买 nike

我正在使用 Java 和 Apache HttpClient 编写一个播客下载器。它适用于大多数 RSS 提要,但此提要失败并出现“406 Not Acceptable ”错误。

链接是http://sqrpt.com/feed/podcast/

我得到的回复是:

HttpResponseProxy{HTTP/1.1 406 Not Acceptable [Server: nginx/1.12.0, Date: Sat, 03 Jun 2017 03:40:17 GMT, Content-Type: text/html; charset=iso-8859-1, Content-Length: 226, Connection: keep-alive] ResponseEntityProxy{[Content-Type: text/html; charset=iso-8859-1,Content-Length: 226,Chunked: false]}}

我的Java代码是:

   HttpClient httpClient = HttpClients.custom().setUserAgent( "Mozilla/5.0" ).build();
HttpGet httpGet = new HttpGet( url );
httpGet.setHeader( "Accept", "*/*" );
httpGet.setHeader( "Accept-Encoding", "gzip, deflate, sdch" );
httpGet.setHeader( "Accept-Language", "en-US,en;q=0.8" );
HttpResponse httpResponse = httpClient.execute( httpGet );
return httpResponse.getEntity();

我不确定如何调试它。大多数帖子都说它的 Accept header 有问题。我已经设置了接受一切,但仍然失败。

当我在 Chrome 中访问该网站时,我收到以下 header 。是否是 304 返回码导致了问题?

General
Request URL:http://sqrpt.com/feed/podcast/
Request Method:GET
Status Code:304 Not Modified
Remote Address:192.185.32.200:80
Referrer Policy:no-referrer-when-downgrade

Response Headers
view source
Connection:keep-alive
Date:Sat, 03 Jun 2017 03:46:27 GMT
ETag:"c06764644cd3ec282be2807a54a3484c"
Server:nginx/1.12.0

Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:sqrpt.com
If-Modified-Since:Fri, 02 Jun 2017 01:36:27 GMT
If-None-Match:"c06764644cd3ec282be2807a54a3484c"
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

我还能尝试什么?

最佳答案

它似乎检查了用户代理。我让它与以下用户代理一起使用:

CloseableHttpClient httpClient = HttpClients.custom().setUserAgent( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" ).build();

关于java - Apache HttpClient 收到 "406 Not Acceptable"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44347720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com