Apache HttpClient 收到“406 不可接受”错误

Apache HttpClient receiving "406 Not Acceptable" error

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

link是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 return 代码导致了问题?

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();