cURL GET请求返回无输出

S. *_*lik 16 curl

我正在发送一个简单的curl请求pinterest.com.使用时PHP没有显示结果.我从命令行尝试了它,没有结果出现.然后我尝试了详细模式curl,它给出了:

curl 7.27.0 (i686-pc-linux-gnu) libcurl/7.27.0 OpenSSL/1.0.1c zlib/1.2.7 libidn/1.25 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp 
Features: Debug GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP
Run Code Online (Sandbox Code Playgroud)

我已经搜索但无法解决.我究竟做错了什么?

命令是:

curl -v pinterest.com
Run Code Online (Sandbox Code Playgroud)

jco*_*ctx 41

检查标题:它只能通过https访问:

$ curl --dump-header - http://pinterest.com/
HTTP/1.1 302 FOUND
Accept-Ranges: bytes
Age: 0
Content-Type: text/html; charset=utf-8
Date: Thu, 18 Jul 2013 19:25:49 GMT
Etag: "d41d8cd98f00b204e9800998ecf8427e"
Location: https://pinterest.com/
Pinterest-Breed: CORGI
Pinterest-Generated-By: ngapp-b7f64694
Pinterest-Version: a8eef3c
Server: nginx/0.8.54
Set-Cookie: csrftoken=A2VQZGarr509JKxrJxiuW2MbrXNdHlUH; Domain=.pinterest.com; expires=Thu, 17-Jul-2014 19:25:49 GMT; Max-Age=31449600; Path=/
Set-Cookie: _pinterest_sess="eJwz84isyvfJcilP1S4szHY20A6MKitJKwwPdi+2tY8vycxNtfUN8TX2c3E19gsJNfAPtLVVK04tLs5MsfXMcjTxq/KsAGJj3/CgHL+QoGzfrLCMSKNAIz93X+PIrHQTIF0eFe6X4ZluawsAh3UjNA=="; Domain=.pinterest.com; expires=Sun, 13-Jul-2014 19:25:49 GMT; Max-Age=31103999; Path=/
Vary: Cookie
Via: 1.1 varnish
X-Varnish: 1991078486
Content-Length: 0
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)

如果您使用该-L选项,您将获得该页面:

$ curl -L http://pinterest.com/
<!DOCTYPE html>
<!--[if IE 7 ]><html lang="en" class="ie7 ielt9 ielt10 en"><![endif]-->
<!--[if IE 8 ]><html lang="en" class="ie8 ielt9 ielt10 en"><![endif]-->
<!--[if IE 9 ]><html lang="en" class="ie9 ielt10 en"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="en" class=" en"><!--<![endif]-->

<head>
    <script>
[snip]
Run Code Online (Sandbox Code Playgroud)

这个链接中是如何使用PHP完成的:

[多年以后......另外,-V--version,不是--verbose,这是小写-v.调用curl -V使它显示版本并忽略任何args,所以你永远不会得到那样的页面.


小智 12

这可能是目标站点 URL 执行重定向时出现问题。

默认情况下,当curl在发出请求后收到重定向时,它不会向新的URL发出请求。作为一个例子,请考虑 URL http://www.facebook.com。当您使用此 URL 发出请求时,服务器会发送 HTTP 3XX 重定向到https://www.facebook.com/。如果您尝试以下操作,您将得到空输出:

$ curl http://www.facebook.com $ 如果您希望 cURL 遵循这些重定向,您应该使用 -L 选项。

$ 卷曲 -L http://www.facebook.com/

您可以使用 pinterest.com 作为示例进行尝试。将“curl pinterest.com”的输出与“curl -L pinterest.com”进行比较