Network Request Tool CURL

Source: Internet
Author: User
Tags http authentication ranges urlencode

Network Request Tool CURL

2017-08-16

Crul is a command-line tool that sends a network request and then gets and extracts data that is displayed in the
"Standard output" (stdout) above.

View Web Source
1 $ Curl Baidu.com
123 <html> <meta http-equiv="Refresh" content="0;url=http://www.baidu.com/" > </html>

If you want to save this page, you can use -o or --output parameters, which is equivalent to using wget
The order.

1 $ Curl-o file_name baidu.com

Auto Jump

Some URLs are automatically redirected. Use -L or --location parameters, curl jumps to the new URL.

1 $ curl-l baidu.com

Display header information

-ior --include the parameter can display the header information of the HTTP response, along with the page code.
-Ior --head parameter is the header information that displays only the HTTP response .

1 $ curl-i baidu.com

123456789101112131415 http/1.1 okdate:wed, 08:21:49 gmtserver:apachelast-modified:tue, 13:48:00 gmtetag: 51-47CF 7e6ee8400 "Accept-ranges:bytescontent-length:81cache-control:max-age=86400expires:thu, 2017 08:21:49 Gmtconnection:keep-alivecontent-type:text/html <html><meta http-equiv= "Refresh" content="0;url=http://www.baidu.com/" > </html>
Show Communication Process

-vor --verbose parameter can display the entire process of an HTTP communication, including port connections and
HTTP request header information.

1 $ curl-v baidu.com

123456789101112131415161718192021222324 * Rebuilt URL to:baidu.com/* Trying 220.181.57.217...* Connected to Baidu.com (220.181.57.217) port (#0) > Get/htt P/1.1> host:baidu.com> user-agent:curl/7.43.0> Accept: */*>< http/1.1 OK < date:wed, 08:24:49 GMT< Server: Apache < Last-modified:tue, Jan 13:48:00 GMT< ETag: "51-47cf7e6ee8400" < Accept-ranges:bytes< content-length: bayi < cache-control:max-age=86400< Expires: Thu, 08:24:49 GMT < connection:keep-alive< content-type: text/html <<html> <meta http-equiv="Refresh" content="0;url=http://www.baidu.com/" > </html> * Connection #0 to host baidu.com left intact

--trace --trace-ascii A more detailed communication process can also be viewed through or by command, after execution by developing
View of the log address

12 $ Curl--trace ${log_path} baidu.com$ curl--trace-ascii ${log_path} baidu.com

http verbs

The default HTTP verb for curl is get, which uses -X parameters to support other verbs.

1 $ curl-x POST baidu.com
Add header information
12 # Use-H or--header can play this role $ curl localhost:8002/test-h "Content-type:application/json"
Send form Information
123456789 # get method is relatively simple, url followed directly with parameters $ curl localhost:8002/ Test?data=xxx # Post method implemented with--data or-D parameters $ curl-x post Localhost:8002/test--data " name=xxx "--data " password=xxx " $ curl-x POST localhost:8002/test-h content-type:application/ X-www-form-urlencoded "-D " Name=win " # Submit JSON data using Application/json $ curl-x POST localhost:8002/test-h Content-type:application/json "-D #如果你的数据没有经过表单编码, you can also let curl encode you, the parameter is '--data-urlencode '. $ curl-x POST localhost:8002/test--data-urlencode "Data=1 2"
File Upload
12 $ curl--form [email protected] localhost:8002/test$ curl--form "[Email Protected];type=text/plain" localhost:8002/Test
referer Field

Need to add request header information Referer where to jump from

1 $ Curl localhost:8002/test--referer ${from_url}

user-agent Field

Use --user-agent or -A can simulate sending user-agent fields

1 $ Curl localhost:8002/test--user-agent "Device"

Cookies
123456 # Sent cookies can be seen in response headers $ curl localhost:8002/test--cookie "Name=ss"#-C Can save the cookies returned by the server to the file $ curl localhost:8002/test-c ${cookie_file}#-B can use this file as cookie information, make subsequent requests. $ curl localhost:8002/test-b ${cookie_file}
HTTP Authentication

Some domains require HTTP authentication, and CURL needs to use --user or -u parameters.

12 # This time the server receives the authorization field in the header message, the value of basic + name:pass Base64 encrypted value $ curl localhost:8002/Test--user Name: APSS

References
    • Curl Website Development Guide

Network Request Tool CURL

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.