Usage of Curl

Source: Internet
Author: User
Tags curl file upload ftp http authentication http post http request ftp protocol ssl connection
Curl Usage Introduction

Curl is a command-line tool that interacts with the server (sending and retrieving information), supports Dict, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, pop3s, RTMP, Protocols such as RTSP, SCP, SFTP, SMTP, SMTPS, Telnet, and TFTP. Curl supports functions such as proxy, user authentication, FTP upload, HTTP POST request, SSL connection, cookies, file transfer, Metalink, etc. URL

Curl supports URLs in several ways:

You can specify multiple URLs, or specify multiple parts of the URL in curly braces.

Http://site. {one,two,three}.com

You can specify a sequence of numbers or letters in brackets.

Ftp://ftp.numericals.com/file[1-100].txt
Ftp://ftp.numericals.com/file[001-100].txt    (with leading zeros)
Ftp://ftp.letters.com/file[a-z].txt

Multiple sequences can be specified.

Http://any.org/archive[1996-1999]/vol[1-4]/part{a,b,c}.html

You can specify any number of Url,curl on the command line to get the contents of the URL in the order specified.

You can specify the number of steps to jump within a range.

Http://www.numericals.com/file[1-100:10].txt
Http://www.letters.com/file[a-z:2].txt

If no protocol prefix is specified, curl attempts to guess the protocol. It chooses the HTTP protocol by default, but when it encounters a common host name, it chooses to try another protocol. For example, Ftp.xxx.com,curl will try the FTP protocol. View HTTP response Headers

Curl-i http://www.baidu.com
viewing the interaction process
Curl-v http://www.baidu.com
GET Request

When an HTTP request is initiated, Curl initiates a GET request by default, or it can be specified by the "-X GET" method.

Curl-x GET http://www.baidu.com
POST Request

When using the Post request method, you need to pass data to the server by specifying "-D".

Curl-x POST http://www.example.com/posts
Delete Request

Delete requests are used to remove server-side data.

Curl-x DELETE HTTP://WWW.EXAMPLE.COM/POSTS/1
put request

Put requests are used to modify server-side data

Curl-x PUT HTTP://WWW.EXAMPLE.COM/POSTS/1
HTTP Authentication

Common HTTP Authentication methods are: Basic certification, digest certification, OAUTH2 certification. Basic Certification

Curl--basic-  u user:password http://www.example.com/posts/1
Digest Certification
Curl--digest-u User:password HTTP://WWW.EXAMPLE.COM/POSTS/1
OAUTH2 Certification
Curl-u clientid:clientsecret-x post-d "Username=test&password=test&grant_type=password&scope=read" Http://www.example.com/oauth/token
curl-h "Authorization:bearer [Bearer]" HTTP://WWW.EXAMPLE.COM/POSTS/1
File Upload

Assume that the file uploads the form as follows:

<form method= "POST" enctype= ' Multipart/form-data ' action= "upload.cgi" >
    <input type=file name=upload >
    <input type=submit name=press value= "OK" >
</form>

You can use Curl to upload files as follows:

Curl--form upload= @localfilename--form press=ok http://www.example.com
User Agent Field

This field is used to represent the client's device information. The server sometimes returns pages of different formats, such as mobile and PC, based on this field, for different devices.

Curl--user-agent "[user agent]" http://www.example.com
Cookies

Curl can send cookies

Curl--cookie "Name1=value1" http://www.example.com
Download Web page
Curl-o file.html http://www.example.com

-o option to save files according to the server's file name

Curl-o http://www.example.com/1.jpg
Proxy Server
Curl-x Proxy server address: Port http://www.example.com
Save Cookie Information
curl-d Cookiefile01.txt http://www.example.com

Use files that store cookie information

curl-d cookiefile02.txt-b cookiefile01.txt http://www.example.com
output detailed interaction information
Curl http://www.example.com--trace-ascii/dev/stdout

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.