Linux Curl Command Parameters detailed

Source: Internet
Author: User
Tags curl http request send cookies

Linux Curl is a tool software that uploads or downloads files at the command line via URL syntax, and it supports multiple protocols such as http,https,ftp,ftps,telnet, which are often used to crawl Web pages and monitor Web server status.

1. Linux Curl Crawl Web page:

Crawl Baidu:

Curl http://www.baidu.com

If found garbled, you can use Iconv transcoding:

Curl http://if rame.ip138.com/ic.asp|iconv-fgb2312

Iconv See: Handling text files with the Iconv command under the Linux/unix system in Chinese garbled problem

  2. Linux Curl Use Agent:

Linux Curl uses HTTP proxies to crawl pages:

Curl-x 111.95.243.36:80 http://if rame.ip138.com/ic.asp|iconv-fgb2312

Curl-x 111.95.243.36:80-u Aiezu:password http://www.baidu.com

To crawl a page using the socks agent:

Curl--SOCKS4 202.113.65.229:443 http://if rame.ip138.com/ic.asp|iconv-fgb2312

Curl--SOCKS5 202.113.65.229:443 http://if rame.ip138.com/ic.asp|iconv-fgb2312

Proxy server addresses can be retrieved from the crawler agent.

  3. Linux Curl Processing cookies

Receive cookies:

Curl-c/tmp/cookies http://www.baidu.com #cookies保存到/tmp/cookies file

Send cookies:

Curl-b "KEY1=VAL1;KEY2=VAL2;" Http://www.baidu.com #发送cookies文本

Curl-b/tmp/cookies http://www.baidu.com #从文件中读取cookies

 4. Linux Curl Send data:

Linux Curl Get way submit data:

Curl-g-D "Name=value&name2=value2" http://www.baidu.com

Linux Curl Post method submission data:

Curl-d "Name=value&name2=value2" http://www.baidu.com #post数据

curl-d a=b&c=d&txt@/tmp/txt http://www.baidu.com #post文件

To upload a file as a form:

Curl-f File=@/tmp/me.txt http://www.aiezu.com

Equivalent to setting the method= "POST" and enctype= ' Multipart/form-data ' two properties for form forms.

  5. Linux Curl HTTP Header processing:

To set HTTP request header information:

Curl-a "mozilla/5.0 firefox/21.0" http://www.baidu.com #设置http请求头User-agent

Curl-e "http://pachong.org/" http://www.baidu.com #设置http请求头Referer

Curl-h "Connection:keep-alive user-agent:mozilla/5.0" http://www.aiezu.com

To set HTTP response header processing:

Curl-i http://www.aiezu.com #仅仅返回header

curl-d/tmp/header http://www.aiezu.com #将http header saved to/tmp/header file

 6. Linux Curl Certification:

Curl-u Aiezu:password http://www.aiezu.com #用户名密码认证

CURL-E Mycert.pem https://www.baidu.com #采用证书认证

 7. Other:

Curl-# http://www.baidu.com #以 "#" Output progress bar

Curl-o/tmp/aiezu http://www.baidu.com #保存http响应到/tmp/aiezu

Linux uses Curl small lessons:

The URL of the HTTP request address is enclosed with "". There may be an error when there are multiple parameters using the & connection.

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.