CURL常用参数

1. CURL简介

cURL是一个利用URL语法在命令行下工作的文件传输工具。它支持文件上传和下载,是综合传输工具。cURL就是客户端(client)的URL工具的意思。

2. 常用参数

  • -k:不校验证书
curl https://baidu.com -k
  • -i:包含响应headers、响应body
➜  ~ curl -i https://baidu.com
HTTP/1.1 302 Moved Temporarily
Server: bfe/1.0.8.18
Date: Tue, 02 Feb 2021 12:50:37 GMT
Content-Type: text/html
Content-Length: 161
Connection: keep-alive
Location: http://www.baidu.com/

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>bfe/1.0.8.18</center>
</body>
</html>
  • -I:只打印响应headers
➜  ~ curl https://baidu.com -I
HTTP/1.1 302 Moved Temporarily
Server: bfe/1.0.8.18
Date: Tue, 02 Feb 2021 12:51:07 GMT
Content-Type: text/html
Content-Length: 161
Connection: keep-alive
Location: http://www.baidu.com/
  • -H: 自定义请求header

  • -d:请求参数,默认为post提交

  • -X:指定请求method,如GET、POST、PUT等

  • -O:将服务器的响应保存到文件

curl -O  /dev/null "https://baidu.com"
  • -L:如果有跳转,则跟随跳转访问
➜  ~ curl https://baidu.com -L
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible c……

3.常用例子

  • 绑定host访问网页:curl -H "Host:www.abc.com" "http://192.168.0.1/test/aa"
posted @ 2021-02-02 20:54  AmyZYX  阅读(1200)  评论(0编辑  收藏  举报