ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

curl的几种用法

2019-11-05 22:00:29  阅读:379  来源: 互联网

标签:www http 请求 几种 sogou curl 用法 com


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 "uploadFile=@test1.txt" 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,http,请求,几种,sogou,curl,用法,com
来源: https://www.cnblogs.com/dgjnszf/p/11801972.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有