curl的几种用法

curl语法: curl [options] <url> 

curl默认直接将http响应的body内容打印输出(不打印http响应头)

User-Agent默认为: curl/版本号 ,如:User-Agent: curl/7.65.3

http请求默认没有Referer

默认使用HTTP/1.1

使用案例

1、发送GET请求,并打印输出http响应的body内容

curl http://www.nyushukka.com/mysqltables.sql

2、发送HEAD请求,只打印输出http响应头

curl --head http://geotar.com/phpbb_db_backup_data.sql

3、使用HTTP/1.0协议

curl --http1.0 http://www.sogou.com/phpbb_db_backup_data.sql

4、跟随302跳转

curl --location http://www.sogou.com/

5、将http响应的body内容写到文件中

curl --output test1.txt http://www.sogou.com/

6、设置Referer请求头

curl --referer "http://www.so.com/" http://www.sogou.com/

7、发送http PUT请求,上传test1.txt文件

curl --upload-file test1.txt http://www.sogou.com/

8、发送POST请求,不进行URL编码,默认使用Content-Type: application/x-www-form-urlencoded

curl --data "username=admin&passwd=123456" http://www.sogou.com/

9、对post请求的数据进行URL编码,"&"符号也会被编码

curl --data-urlencode "username=admin&passwd=123456" http://www.sogou.com/

10、忽略https证书错误

curl --insecure https://frostyfactory.club/strandz.png

11、添加http请求头

curl --header "Cookies: user=admin" http://www.baidu.com/strandz.png

12、请求ipv6地址

curl --ipv6 http://www.google.com/

13、post请求上传文件,uploadFile是form表单的名字

curl -F "[email protected]" http://www.baidu.com/

POST请求的形式像下面一样:
/****
    POST / HTTP/1.1
    Host: www.so.com
    User-Agent: curl/7.65.3
    Accept: */*
    Content-Length: 269
    Content-Type: multipart/form-data; boundary=------------------------bf349de57ad4ce17

    --------------------------bf349de57ad4ce17
    Content-Disposition: form-data; name="uploadFile"; filename="test1.txt"
    Content-Type: text/plain

    <head><title>302 Found</ti
    <center><h1>302 Found</h1></center>
    <hr><cent
    --------------------------bf349de57ad4ce17--
****/



猜你喜欢

转载自www.cnblogs.com/dgjnszf/p/11801972.html