FreeKB - curl (GET)
Linux Commands - curl (GET)

The curl command without any options will:

  • Display the contents of a file on a server
  • Display the result of a GET request

 


Display the contents of a file on a server

In this example, the contents of the index.html file on the www.example.com web server is displayed.

curl http://www.example.com/index.html
. . .
<html>
  <body>
    Hello World
  </body>
</html>

 


Display the result of a GET request

Let's say www.example.com contains index.php with following markup.

<?php echo $_GET['foo']; ?>

 

Entering the following URL in a web browser would display "bar".

http://www.example.com/index.php?foo=bar

 

Likewise, the following curl command would also display "bar".

curl http://www.example.com/index.php?foo=bar
. . .
bar

 


-X or --request GET

The -X or --request option is used to define the method being used, such as GET, POST, PUT, or DELETE.  When the -X or --request option is not used, the GET method will be used. Thus, the following commands both display the contents of the index.html page from the www.example.com web server.

curl http://www.example.com/index.html
curl -X GET http://www.example.com/index.html

 


--url

The --url option is used to define the URL being requested. This option is typically not needed, thus the following commands both display the contents of the index.html page from the www.example.com web server.

curl http://www.example.com/index.html
curl --url http://www.example.com/index.html

 


Redirection

Redirection can be used to transfer the contents of the target file to a file on the local PC. For example, to transfer the contents of the index.html file to local.file.

curl http://www.example.com/index.html > local.file

 

Similarly, the -o option followed by the target file and then the URL will transfer the target file to the local PC.

curl -o index.html http://www.example.com/

 


Public Certificate

The following command can be used to determine the public certificate that was requested from a particular URL.

curl --verbose --insecure https://www.example.com

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 20309 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |