Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL GET Request Returns No Output

Tags:

curl

I'm sending a simple curl request to pinterest.com. When I do it using PHP no result is shown. I tried it from command line and no result showed up. Then I tried the verbose mode in curl and it gives:

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 

I have searched but could not sort out. What am I doing wrong?

The command is:

curl -v pinterest.com 
like image 798
S. A. Malik Avatar asked Jul 18 '13 19:07

S. A. Malik


People also ask

What does it mean if curl returns nothing?

The error “empty reply from server” indicates that a zero-length response was received. This means no HTTP headers or content, simply a closed TCP connection with no HTTP payload is transmitted. curl: (52) Empty reply from the server is a server related issue.

How do I print a curl response?

By default, curl doesn't print the response headers. It only prints the response body. To print the response headers, too, use the -i command line argument.

Why is my curl command not working?

We might have come across errors like “curl: command not found” while working in the terminal. This type of error comes due to only one reason: the relevant package is not installed. Curl is a very popular data transfer command-line utility used for downloading and uploading data from or to the server.


2 Answers

Check the headers: It's only accessible by 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 

If you use the -L option you'll get the page:

$ 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] 

Here in this link is how it's done with PHP:

[Years later...] also, -V is --version, not --verbose, which is lowercase -v. invoking curl -V causes it to display the version and ignore any args, so you would never get the page that way anyway.

like image 118
jcomeau_ictx Avatar answered Oct 22 '22 10:10

jcomeau_ictx


It could be a problem with the target site URL doing a redirect.

By default, when curl receives a redirect after making a request, it won't make a request to the new URL. As an example of this, consider the URL http://www.facebook.com. When you make a request using to this URL, the server sends a HTTP 3XX redirect to https://www.facebook.com/. If you try the following you will get an empty output:

$ curl http://www.facebook.com $ If you want cURL to follow these redirects, you should use the -L option.

$ curl -L http://www.facebook.com/

You could try it out with pinterest.com for your example. Compare the output of "curl pinterest.com" with "curl -L pinterest.com"

like image 45
Gfinlay Avatar answered Oct 22 '22 09:10

Gfinlay