Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
维基媒体网站上的“curl”问题_Curl_Mediawiki_Wget_Wikipedia_Wikimedia - Fatal编程技术网

维基媒体网站上的“curl”问题

维基媒体网站上的“curl”问题,curl,mediawiki,wget,wikipedia,wikimedia,Curl,Mediawiki,Wget,Wikipedia,Wikimedia,我无法使用curl从维基百科和wikiquote等维基媒体网站下载任何内容 当我尝试时,我得到: ~$ /usr/bin/curl -v "http://en.wikipedia.org/wiki/Celsius" * Trying 2620:0:863:ed1a::1... * TCP_NODELAY set * Connected to en.wikipedia.org (2620:0:863:ed1a::1) port 80 (#0) > GET /wiki/Celsius HT

我无法使用
curl
从维基百科和wikiquote等维基媒体网站下载任何内容

当我尝试时,我得到:

~$ /usr/bin/curl -v "http://en.wikipedia.org/wiki/Celsius"
*   Trying 2620:0:863:ed1a::1...
* TCP_NODELAY set
* Connected to en.wikipedia.org (2620:0:863:ed1a::1) port 80 (#0)
> GET /wiki/Celsius HTTP/1.1
> Host: en.wikipedia.org
> User-Agent: curl/7.52.1
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 19 May 2017 22:09:49 GMT
< Server: Varnish
< X-Varnish: 350654144
< X-Cache: cp4017 int
< X-Cache-Status: int
< Set-Cookie: WMF-Last-Access=19-May-2017;Path=/;HttpOnly;secure;Expires=Tue, 20 Jun 2017 12:00:00 GMT
< Set-Cookie: WMF-Last-Access-Global=19-May-2017;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Tue, 20 Jun 2017 12:00:00 GMT
< X-Client-IP: 2605:a601:1127:7d00:35a2:5040:e002:9949
< Location: https://en.wikipedia.org/wiki/Celsius
< Content-Length: 0
< Connection: keep-alive
< 
* Curl_http_done: called premature == 0
* Connection #0 to host en.wikipedia.org left intact

有什么问题吗?

在chrome和其他浏览器中,您可以选择将请求作为curl获取

启动开发者工具,刷新页面,右键单击网络选项卡下的第一个链接。右键单击它,然后单击“复制”,然后单击“复制为卷曲”

有效的示例:

curl 'https://en.wikipedia.org/wiki/Celsius' -H 'pragma: no-cache' -H 'dnt: 1' -H 'accept-encoding: gzip, deflate, sdch, br' -H 'accept-language: en-US,en;q=0.8,ro;q=0.6,la;q=0.4' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/531.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/511.36' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'cache-control: no-cache' -H 'authority: en.wikipedia.org' -H 'WMF-Last-Access=19-May-2017; WMF-Last-Access-Global=19-May-2017' --compressed
卷曲版本:

curl 7.51.0
命令不起作用的原因是需要指示cURL遵循重定向(您还将注意到您提供的示例中的302):


谢谢这对我也适用。我不知道为什么这样做&简单的curl调用不起作用。简单的curl调用对您有用吗?从您的例子中,我认为您在添加-v作为选项时不应该发出该curl请求。@DanielMahler我对我的答案做了一个小的调整,提供了一个小的见解。谢谢,我还了解到使用https url可以在没有任何标志的情况下工作。我猜重定向是http->httpst,太棒了!您将在大规模上获得更好的性能。Wikipedia仅限于HTTPS。
curl 7.51.0
curl -L http://en.wikipedia.org/wiki/Celsius