cURL

cURL is a command line tool and library for transferring data with URLs. The command supports a number of different protocols, including HTTP, HTTPS, FTP, SCP, and SFTP. It is also designed to work without user interaction, like in scripts.

Installation

Install the curl package.

Usage

Downloading

A common use case for cURL is to download the resource to a specified file:

$ curl -o file name URL

If the URL contains the file name, you can save the resource directly to a file of that name:

$ curl -O URL

Similarly, you can use -J to accept a hint from an HTTP server (from the Content-Disposition header) for what the file should be named. If combined with -O, curl will use the file name specified by the URL if the HTTP server does not return a file name hint in its response.

Alternatively you can print the resource to stdout by omitting the output options:

$ curl URL

HTTP POST

You can use cURL to make HTTP POST requests:

$ curl -d 'request body' URL

If the request body cannot fit on the command line, cURL can read it from a file:

$ curl -d @file name URL

Sometimes, you may need to specify a custom value for the Content-Type header (cURL's default is application/x-www-form-urlencoded). You can do this with -H. For example, if you wanted to make a POST request with a JSON body:

$ curl -d 'json body' -H 'Content-Type: application/json' URL
gollark: In case I need the raw HTML later.
gollark: It doesn't ignore robots.txt, I just manually whitelist sites.
gollark: But it's non-evil, so I would set it to 0, silly.
gollark: When it downloads a page, it stores:- the raw HTML of it, gzipped- the extracted text of it- a timestamp- the frequency of every word (well, token) in the page- every link from that page
gollark: Because of the way it works it uses a *lot* more space than just the size of the page, so it would use all my storage very fast.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.