Linux Curl uses a detailed description of common applications

Source: Internet
Author: User

Curl


1 HTTP Timeout

-m specifies that the time-out is equal to--connect-timeout


2 output to NULL

-o/dev/null not output, normal is output HTML format


3-w Specifying format output


4-s remove the output from all status information


5-f uploading a form


6-e/--referer <URL> designation Referer


7-h/--header


8-v View the detailed request setup information, you can see the header


9-l when redirecting, initiate a new request


--user Certified User Name


11-xget Request method, default is Get


The--data-binary is uploaded in binary mode without any processing

The--data-urlencode is roughly equivalent to-D or--data


14-o Write output to <file> instead of stdout


15-x Proxy Access


Three differences:

-d/--data is the same as--data-ascii. To post data purely binary, you should instead use the--data-binary option. To Url-encode the

Value of a form field--data-urlencode.





Apply One: Timeout setting


Curl-m 3-o/dev/null-s-w%{http_code} "\ n" www.letuknowit.com


Just output the status code and wrap the line "\ n"



Note If the timeout Http_code is 000



Application two: Probing the time point of the web to establish the response of each link


Curl-o/dev/null-s-W%{time_connect}:%{time_starttransfer}:%{time_total}:%{time_namelookup} "\ n" http://www.canada.com


0.081:0.272:0.779:0.356


Listing 1 shows how to perform a curl command on a popular news site. The output is usually HTML code, which is sent to the/dev/null.-s parameter with the-o parameter to remove all state information. The-w parameter lets curl write out the status information for the timers listed in table 1:


Table 1. The timers used by curl


Timer Description

Time_connect The time it took to establish a TCP connection to the server

Time_starttransfer The time it takes for the WEB server to return the first byte of data after making a request

Time_Total The time it took to complete the request

Time_namelookupDNS resolution time, from the start of the request to the time the DNS resolution is completed (remember to turn off the Linux NSCD service test)

Speed_download Download speed, units-bytes per second.

These timers are relative to the start time of the transaction, even before the Domain Name Service (DNS) query. Therefore, after the request is made, the time that the WEB server takes to process the request and start sending the data back is 0.272–0.081 = 0.191 seconds. The time it takes the client to download data from the server is 0.779–0.272 = 0.507 seconds.





Application three: Upload form data upload image

Curl-e "Http://www.kkfang.com/cuizhiliang"-F "[Email protected]/testtest_1111.jpg" "http://upload.kkfang.com/ Upload/housea.html "



Example:

-f/--form <name=content

Curl-f "[Email protected];filename=nameinpost" url.com



A file path is followed by @



Application four: Simulate modifying header head


-H "Cache-control:no-cache"

curl-x127.0.0.1:6081 "HTTP://WWW.KKFANG.COM/BJ"-H "user-agent:" Googlebot ""


Multiple header headers used together


Curl-v-i-h "Host:www.kkfang.com"-H "User-agent:ba" http://www.kkfang.com


Curl-v-i-h "Host:www.kkfang.com"-H "user-agent:ba"-H "Cache-control:no-cache" http://www.kkfang.com





Application Five: redirect The Master station

Curl-il http://www.dianping.com


Will 302 jump to the City list page location:/citylist


301 redirect vs. 302 redirect

302 redirects are temporary redirects, and search engines crawl new content and keep the old URLs. Because the server returns 302 code, the search engine thinks the new URL is only temporary. SEO 302 Better than 301

301 redirects are permanent redirects, and search engines also replace old URLs with redirected URLs while crawling new content.




Application Six:--user calls Jenkins API to get the configuration file

Curl-xget Http://jenkins.anhouse.com.cn/job/ST-ananzu-service/config.xml--user cuizhiliang344:czl110123






Apply seven: Post data, plus shell variable delivery, execute Jenkins job and modify data

/usr/bin/curl-m 5-s-W%{http_code}-X POST jenkins_url/job/job_name/build--data-urlencode json= ' {"parameter": [{"NAME ":" id "," value ":" 123 "}, {" Name ":" ' ${_task_name} ' "," value ":" High "}]} '




Application Eight: Output content

Curl-s-xget http://jenkins.anhouse.com.cn/job/ST-ananzu-service/config.xml--user cuizhiliang344:czl110123-o Config.txt


or use > for redirection

Curl-s-xget http://jenkins.anhouse.com.cn/job/ST-ananzu-service/config.xml--user cuizhiliang344:czl110123 > Config.txt



This article is from the "Remnant Sword" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1962915

Linux Curl uses a detailed description of common applications

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.