FreeKB - Curl -X --request GET
Curl - -X --request GET

The curl command without any options will:

  • Display the contents of a file on a server, such as a web server or FTP 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>

 

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

~]# curl http://www.example.com/foo.json
[
 {
  "foo":"bar"
 }
]

 

By default, curl uses the GET method, thus there is no need to use the -X or --request option when using the GET method. The following commands will both return the content of the index.html page. The -X or --request option must be used when using any other method (POST, PUT, DELETE). 

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

 


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

 


Download file

The -o or --output option can be used to redirect the content of the remote file to a file on your local system.

 


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

 


Authentication

Let's say access to this page require basic authentication (username/password). The -u or --user option can be used to include a username and password in the request.

curl --user john.doe:itsasecret https://www.example.com/foo.html

 



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 ca713 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   |