curl使用

简介: curl使用

这是我常用的参数,没涉及到的参数自行百度,我放几个链接,自己可以去看看。


阮一峰curl

https://baike.baidu.com/item/curl/10098606?fr=aladdin

https://catonmat.net/cookbooks/curl


主要用的参数:-F -H -G -d -i -L -o -v


curl POST 上传文件:

curl -F "myfile=@shell.php" http://www.uschinaecp.org/jQuery-File-Upload/server/php/files/upload.php"


curl post请求提交表单

curl -d "birthyear=1905&press=OK"  www.hotmail.com/when/junk.cgi


curl发送get请求(不带任何参数)

curl  https://www.baidu.com
curl "www.hotmail. com/when/junk.cgi?birthyear=1905&press=OK"
或者
curl -G -d 'q=kitties' -d 'count=20' https://google.com/search  指定get参数


参数:

上传文件时要用@+filename
要使用http加密传输,url前就加上https://  一般不加直接www.xxx.com?xx=xx也可以
-A 指定UA,curl默认UA是curl/[version]
    curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.com
    curl -A '' https://www.google.com  //表示移除UA
-H  表示在请求头中附加参数,使用-H可以加UA 比如-H "'User-Agent: php/1.0"
-b 指定cookie 
  eg:curl -b "foo=bar;foo2=bar2" https://www.google.com
  curl -b cookies.txt https://www.google.com  //cookie.txt中包含的是服务器保存在本机的cookie
-c  cookie将服务器设置的cookie写入本地一个文件
  curl -c cookie.txt https://www.google.com
-d  发送指定post要发送的数据体(参数/文件)
  -d 发送文件时,要用@+filename
  eg:curl -d 'login=name&passwd=123' -X POST https://www.google.com
  或者curl -d 'login=name' -d 'passwd=123' -X POST https://www.google.com
  curl -d '@data.txt' https://www.google.com
  注:使用-d参数后,HTTP请求会自动加上标头Content-Type: application/x-www-form-urlencoded,并且会自动将请求转为POST,所以-X POST可以省略
--data-urlencode 发送指定post要发送的数据体(参数/文件)
  --data-urlencode等同于-d,区别在于会自动将发送的数据进行url编码
  eg:curl --data-urlencode 'comment=hello world' https://google.com/login
-e  设置请求头referer 字段
  eg:curl -e 'https:google.com?q=example' https://www.example.com
  通过-H 添加 也一样  -H 'Referer:https://google.com?q=example'
-F  用来向服务器上传二进制文件
  eg:curl -F 'file=@photo.png' https://google.com
  注:上述命令会自动给http请求头加上Content-type: multipart/form-data 然后将文件photo.png 作为file字段上传
  -F参数可以指定 MIME 类型。
  $ curl -F 'file=@photo.png;type=image/png' https://google.com/profile
上面命令指定 MIME 类型为image/png,否则 curl 会把 MIME 类型设为application/octet-stream。
  -F参数也可以指定文件名。
  $ curl -F 'file=@photo.png;filename=me.png' https://google.com/profile
上面命令中,原始文件名为photo.png,但是服务器接收到的文件名为me.png。
-G  参数用来构造 URL 的查询字符串。
  $ curl -G -d 'q=kitties' -d 'count=20' https://google.com/search
上面命令会发出一个 GET 请求,实际请求的 URL 为https://google.com/search?q=kitties&count=20。如果省略--G,会发出一个 POST 请求。
  如果数据需要 URL 编码,可以结合--data--urlencode参数。
  $ curl -G --data-urlencode 'comment=hello world' https://www.example.com
-H  参数添加 HTTP 请求的标头。  
-i  打印服务器回应的HTTP标头
  eg:curl -i https://www.example.com
-k  跳过SSL检测
  eg:$ curl -k https://www.example.com  上面命令不会检查服务器的 SSL 证书是否正确。
-L  参数会让http请求跟随服务器重定向,curl默认不跟随重定向
  eg:curl -L -d "tweet=hi" https://www.google.com  -d是post参数get参数要用-G -d ...
-o  将服务器返回内容保存成文件,等同于wget
  eg:curl -o html.html https://www.google.com
-v  输出通信的详细过程
-X  指定http请求方式   
  使用-d --data-encode 时会自动转为post请求 所以可以省略


相关文章
|
6天前
|
测试技术 网络安全 数据安全/隐私保护
curl 命令的使用一例
curl 命令的使用一例
52 0
|
6天前
|
安全 网络协议 网络安全
curl使用
curl使用
68 0
|
Linux Windows
curl命令使用
curl命令使用
432 0
curl命令使用
|
Web App开发 JSON 运维
快来看,敖丙还不会curl
不知道大家在平时有没有用过curl,之前我是没怎么用的,最近也开始用起来了。
159 0
快来看,敖丙还不会curl
|
测试技术 Linux Python
我差一点误会了curl
记录一次curl使用遇到的问题
563 0
|
域名解析 XML 存储
Curl
Curl参数
|
数据安全/隐私保护
curl常见命令
下载文件 curl 命令正常情况下将收到的内容打印到标准输出,通过-o或者-O参数将下载内容保持 curl -o zxy.html http://www.baidu.com #将文件保存为zxy.html curl -O http://www.gnu.org/software/gettext/Manuel/gettext.html curl -O -# http://www.gnu.org/software/gettext/Manuel/gettext.html # -#表示下载时刻显示进度条。
940 0
|
Web App开发 PHP
|
Web App开发 Linux 网络安全