Linux curl command

Source: Internet
Author: User

Curl www.csdn.net

Request csdn and return the content of the csdn homepage. To write the returned content to a file, use the following statement.

Curl www.csdn.net> file.html

You can also use the following statement:

Curl-O file.html www.csdn.net

This will display the download progress bar. If you do not want it to display the download progress bar, you only need to add the-S parameter, that is, curl-S-O file.html www.csdn.net.

To use the resumable upload function, you only need to add the-C parameter. That is: curl-c-o file.html www.csdn.net.

Curl also supports proxy access to the network. As follows:

Curl-x 192.168.1.1: 9090-O file.html www.csdn.net

If you want to save the cookie information on the page, add the-D parameter. As follows:

Curl-D cookie.txt-O file.html www.csdn.net

How can I use the last cookie during the next access? Add the-B parameter.

Curl-B cookie.txt-0 file.html www.csdn.net

How can I add browser information to a request? Use the-a parameter. As follows:

Curl-a "Mozilla/5.0 (Windows NT 6.1; wow64)"-B cookie.txt-0 file.html www.csdn.net

How can I cheat the server and tell the server that I came from a website? Use-E:

Curl-e www.a.com-O file.html www. B .com

You can cheat www. B .com. You are from www.a.com.

You can use-O to download files. -O can be used to download files based on the file name on the server.

Curl-O www.a.com/test.jpg

In addition, curl supports batch download using regular expressions.

Curl also supports the-R parameter for multipart download. For example, a song a.mp3 is downloaded. Run the following command:

Curl-R 0-10240 "A. Part1" www.a.com/a.mp3

Curl-r 10241-20480 "A. Part2" www.a.com/a.mp3

In Linux, you can use Cat A. Part *> a.mp3 to merge the file into a whole.

Curl also supports FTP download. The usage is as follows:

Curl-u Username: Password ftp: // ip: Port/path/file or

Curl ftp: // username: password @ IP: Port/path/File

I talked about downloading and uploading. The parameter used for upload is-t.

For example, uploading a file to FTP:

Curl-T file.txt-u Username: Password ftp: // ip: Port/path

Or

Curl-T file.txt http://www.a.com/

In this case, the http put method is used.

How can we develop various HTTP methods? You do not need to specify the get method because it is used by default.

For example: curl http://www.a.com/login? Username = Shan & Password = 1234

Use the-D parameter when using the POST method. For example:

Curl-d "username = Shan & Password = 1234" http://www.a.com/login

To upload JSON data, use the following statement:

Curl-h "accept: Application/JSON"-h "Content-Type: Application/JSON"-X Post-d' {"title": "a new test ", "content": "hahahah", "author": "Shan", "status": 0, "created": "2013-08-10
12:03:04 "} 'http://a.test.com/api/post

To upload JSON data using the put method, run the following command:

Curl-h "accept: Application/JSON"-h "Content-Type: Application/JSON"-x put-d' {"title": "A New test1 "}'

Http://a.test.com/api/post


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.