cURL不起作用,但同一站点适用于浏览器

时间:2016-07-02 12:58:52

标签: linux curl libcurl

使用cURL表单linux服务器访问该站点时返回错误的原因是什么。但是在chrome中打开这个网站成功了。

3 个答案:

答案 0 :(得分:4)

在发送请求时查看浏览器标头,并向cURL请求添加相同的标头。某些服务器需要一些浏览器发送默认但不是cURL的标头。

答案 1 :(得分:1)

我在curl上遇到301 Moved Permanently错误,但正在使用浏览器。

但是当我看得更深的时候,Location移动到了位置,这将是有效的。这可以在服务器使用TLS时进行。

$ curl -v http://www.shaharma.com/location/v1/US/zipcode/98104
*   Trying 172.111.99.100...
* TCP_NODELAY set
* Connected to www.shaharma.com (172.111.99.100) port 80 (#0)
> GET /location/v1/US/zipcode/98104 HTTP/1.1
> Host: www.shaharma.com
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Content-Length: 0
< Location: https://www.shaharma.com/location/v1/US/zipcode/98104
< Cache-Control: max-age=0
< Expires: Fri, 01 Dec 2017 19:40:14 GMT
< Date: Fri, 01 Dec 2017 19:40:14 GMT
< Connection: Keep-Alive
< Set-Cookie: UID=52679eee-c06c-49fc-893a-69fd7e46bad0; expires=Fri, 25-Feb-2028 19:40:14 GMT; path=/; domain=.shaharma.com
< Set-Cookie: SID=1ada5fa9-0ace-4f4e-b75b-7a756b8da934; path=/; domain=.shaharma.com
< Set-Cookie: shaharma_loc_lb=p-loc-w; expires=Fri, 01-Dec-2017 19:50:14 GMT; path=/; domain=.shaharma.com
< Set-Cookie: bby_rdp=l; expires=Sat, 02-Dec-2017 19:40:14 GMT; path=/; domain=.shaharma.com
< 
* Connection #0 to host www.shaharma.com left intact

此外,您可以转到浏览器并查看将包含标题信息的网络。

headers

答案 2 :(得分:0)

要避免/禁止SSL错误,请使用-k标志,即

curl -k ...