Linux curl 命令返回 http/1.1 406 不可接受的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8653271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:50:16  来源:igfitidea点击:

curl command return http/1.1 406 not acceptable error

phplinuxapachecurlcompression

提问by clickme please

I am using below command line curl for knowing if my site supports compressing and caching

我正在使用下面的命令行 curl 来了解我的站点是否支持压缩和缓存

curl --head --compress http://www.mysite.com

curl --head --compress http://www.mysite.com

it returns the following result

它返回以下结果

Http://1.1 406 Not Acceptable
Date: Wed, 28 Dec 2011 07:41:32 GMT
Server: Apache
Content-Type: text/html; charset-iso-8859-1

what do you think about the problem? Thanks

你怎么看这个问题?谢谢

回答by Jory Geerts

From the HTTP/1.1 standard:

来自 HTTP/1.1 标准:

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

Unless it was a HEAD request, the response SHOULD include an entity containing a list of available entity characteristics and location(s) from which the user or user agent can choose the one most appropriate.

请求标识的资源只能根据请求中发送的accept头生成具有不可接受的内容特征的响应实体。

除非是 HEAD 请求,否则响应应该包含一个实体,其中包含可用实体特征和位置的列表,用户或用户代理可以从中选择最合适的一个。

So drop the --head and you shouldsee whats wrong.

所以放下--head,你应该看看有什么问题。

The 406 may just be what is proving you right - the server doesn't support compression. :)

406 可能只是证明您是正确的 - 服务器不支持压缩。:)

回答by Yotam

In some case I had, faking the agent solved this problem, by using:

在某些情况下,我通过使用伪造代理解决了这个问题:

curl -A "Mozilla/4.0"

Similarly using libcurl C-API:

同样使用libcurl C-API

curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0");