Curl Parameters



  • Prevent curl from reading the default file by using -q as the first command line parameter, like: curl -q www.thatsite.com Force curl to get and display a local help page in case it is invoked without URL by making a config file similar to.
  • How to find the version of curl? # curl -V OR # curl –version. Note: If your system.

Whenever your have a doubt use man. Issue man curl and read about -d switch.-d, -data (HTTP) Sends the specified data in a POST request to the HTTP cause curl to pass the data to the server using the content-type -d, -data is the same as -data-ascii.data-raw is almost the ter. A callback accepting two parameters. The first is the cURL resource, the second is a string with the header data to be written. The header data must be written by this callback. Return the number of bytes written. CURLOPTPASSWDFUNCTION: A callback accepting three parameters.

cURL is a solid and simple tool that allows transferring data from and to any server with command line using various protocols including HTTP. This article is a short introduction on how to use cURL effectively along with some lesser known tricks.

Interacting with protocols

Getting a HTML page from a server is as simple as putting a HTTP URL as first cURL argument.

cURL makes a GET request to the specified URL and brings back the results into the command line. This output can be saved to a file using -O parameter (-o if you want to use your own name for the file).

Getting a file from a FTP server is also easy:

There are two handy parameters, especially useful for debugging:

Curl
  • -i or --include which puts headers data returned by the server in the output
  • -v or --verbose which includes in the output both, headers data sent to the server and returned by the server

Sending data to the server

-d or --data parameter allows to specify data to send to the HTTP server. It simulates a form submission. Invoking cURL with this parameter will make a POST request (instead of default GET). cURL will set Content-Type as application/x-www-form-urlencoded automatically. Multiple fields should be separated by & or specified with a separate -d parameter for each field.

It is also possible to send data in JSON format. Content-Type has to be explicitly set to application/json as it is used by the server to decide how to handle the incoming data.

Curl Header

For convenience, the data can be also read from a file or from the standard input:

We could also specify the Accept header which is used to tell the server what content types we accept as a client. The server will respond with Content-Type that will inform us about the content type of the returned data. As a result, Content-Type header is used to specify the type of data being sent both, from and to the client.

RESTful Interaction

Curl

cURL comes in handy when interacting with RESTful APIs. In the examples below, we will use RESTful API built yesterday.

Let's start by creating a simple resource from a JSON. As mentioned earlier, POST request override default GET when using -d parameter.

For a resource update we will specify PUT method with -X or --request parameter.

It is also possible to simulate PUT method with POST by using a special X-HTTP-Method-Override header.

Finally we can delete the resource using DELETE method.

Similar to PUT, we can ask the server to override a POST request ifsetting DELETE explicitly is not possible.

Login with Basic Auth

HTTP Basic authentication is a simple way to secure web pages. If SSL is not used, the credentials are passed in plain text. cURL has -u|--user option that allows to login using that method.

Login with Cookie

cURL can be also used to login using a cookie. In the exampleb below, we simulate a form submission of login credentials, and we store returned cookies in a file with -c parameter. For following requests, we can then use that cookies (-b parameter) to authenticate. The process simulates how a browser handles the session.

Things may get a little tricker when CSRF validation is enabled. In such case it would be also necessary to extract CSRF token.

curl is an command line tool for transferring data between two servers. Other than downloading files curl also used to performs multiple tasks by the applications, services etc. Curl supported a verity of protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP) for file transferring.

The curl is powered by the libcurl for all the transfer-related tasks on system.

  • Syntax:

    Example: Open a terminal on your system and type:

  • You will see the website content on terminal. This is the most basic uses of curl command line.

URL Syntax

The URL syntax is completely protocol-dependent with cURL. Before reading more about parameters or example, you must know the URL formats, you can use with curl.

  • Use braces and quotes to define multiple URLs in single. Here braces expands to multiple urls. For example:

    Becomes, http://www.one.com, http://www.two.com and http://www.three.com.

  • You can also define a range by using [] as in:
  • You can also specify to use every N’th letter or number from a defined range.

    Here the first url will refer to every 5’th file and second url with refer to every second letter.

CURL Command Options

curl command comes with large number of command line options. Which provides it great flexibility to perform various tasks. Here we will describe you some frequently used command options with curl command.

Curl Parameters List

  • -s or --silent – While using this option, the command runs silently in background. No progress will be displayed on screen. Only the command result will be displayed.
  • -O – The capital letter “O” is used to download a file using curl command. The filename will remain same on local system as on remote.
  • -o or --output FILE – Use this option to write all data to file instead of displaying at standard output.

    While downloading a file, use this option to save file on local machine with provided name.

  • -I or --head – Use this option to view the document information only. This will not download the content or file from server.

    This is also useful to view header only details for a domain.

  • -u or --user – Use this option to send authentication details with curl request. It is useful to download files from authenticated ftp server or web servers.
  • -T – curl also allows you to upload a file to remote ftp server. To upload a file use -T option followed by the local file name. If the remote server required authentication, make sure to provide authentication details with “-u” option.
  • -x or -–proxy – You can route your curl request via a proxy server. You can define proxy server with -x option.

Similar tutorials:

Conclusion

Parameters

Curl Pass Parameters

In this tutorial, you have learned about curl command line options with examples. For more command line options view curl man pages (man curl) or use curl --help command.