$curl -svI ab.text.com/jdk-8u101-linux-x64.tar.gz
......
> HEAD /big/SGWS5.PC6game.zip HTTP/1.1 #默认协议为1.1
$curl -0 -svI ab.text.com/jdk-8u101-linux-x64.åtar.gz
......
> HEAD /big/SGWS5.PC6game.zip HTTP/1.0 #默认协议已经修改为http 1.0了
$curl -A 'Mozilla/5.0' -I ab.text.com/jdk-8u101-linux-x64.tar.gz
# tail -1 /data/logs/www/ab.text.com.log #通过下面的日志就可以看出使用的是Mozilla进行访问,而不是通过curl访问的
10.168.1.102 | - | 22/Oct/2019:09:53:53 -0400 | HEAD /jdk-8u101-linux-x64.tar.gz HTTP/1.1 | 200 | 256 | 0 | ab.text.com | - | Mozilla/5.0 | - | - | - | 0.000 | -
#发送单个cookie
$curl -b "test=test1" -vI ab.text.com/jdk-8u101-linux-x64.tar.gz
* Trying 10.28.88.199...
* TCP_NODELAY set
* Connected to ab.text.com (10.28.88.199) port 80 (#0)
> HEAD /jdk-8u101-linux-x64.tar.gz HTTP/1.1
> Host: ab.text.com
> User-Agent: curl/7.54.0
> Accept: */*
> Cookie: test=test1
#发送多个cookie 语法:“name1=value1;name2=value2” 中间用;隔开
$curl -b "test=test1;test2=test2" -vI ab.text.com/jdk-8u101-linux-x64.tar.gz
* Trying 10.28.88.199...
* TCP_NODELAY set
* Connected to ab.text.com (10.28.88.199) port 80 (#0)
> HEAD /jdk-8u101-linux-x64.tar.gz HTTP/1.1
> Host: ab.text.com
> User-Agent: curl/7.54.0
> Accept: */*
> Cookie: test=test1;test2=test2
#读取本地cookei 语法: -b filename(没有看到cookie信息)
$curl -b 1.txt -vI ab.text.com
$curl -c cookie.txt -vL www.baidu.com #需要加 -L 才能看到set-cookie信息
......
< Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
$ls cookie.txt
cookie.txt
$cat cookie.txt
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
.baidu.com TRUE / FALSE 1571841604 BDORZ 27315
注:将post请求体发送给服务器,使用-d参数后,header请求头会自动添加 application / x-www-form-urlencoded 标头,也会把请求方法自动转换为POST方法,不用 -X post 用法: -d '{具体数据}'
#用法基本是这样
$ curl -H "Content-Type:application/json" -XPUT 'http://10.28.88.199:9200/ac/book/1?pretty' -d '{"title":"创始道纪"}'
$curl -D header.txt -vI www.baidu.com
s$ls header.txt
header.txt
$cat header.txt
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 277
Content-Type: text/html
Date: Tue, 22 Oct 2019 15:07:55 GMT
Etag: "575e1f72-115"
Last-Modified: Mon, 13 Jun 2016 02:50:26 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
$curl -e "ab.text.com/a.html" http://www.baidu.com
$curl -H "referer:ab.text.com/a.html" http://www.baidu.com # -H "referer:" 与 -e效果一样
#为什么这么做,那我现在也测试不出来
--cert-type
#一般用法
$curl -F '[email protected]' ab.text.com/user
#指定文件类型 使用type指令
$curl -F '[email protected];type=text/plain' ab.text.com/user
#改名(将文件传送到服务器之后进行改名) 使用filename指令
$curl -F '[email protected];filename=cookie' ab.text.com/user
注:有个前提是你的服务器可以接收你所上传的数据,并且进行处理
#默认访问方式
$curl -v -d 'c=wwert' -d 'count=30' ab.text.com
* Rebuilt URL to: ab.text.com/
* Trying 10.28.88.199...
* TCP_NODELAY set
* Connected to ab.text.com (10.28.88.199) port 80 (#0)
> POST / HTTP/1.1
> Host: ab.text.com
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 16
> Content-Type: application/x-www-form-urlencoded
#加了 -G 请求方法立马变get,并且URI变成/?c=wwert&count=30
$curl -v -G -d 'c=wwert' -d 'count=30' ab.text.com
* Trying 10.28.88.199...
* TCP_NODELAY set
* Connected to ab.text.com (10.28.88.199) port 80 (#0)
> GET /?c=wwert&count=30 HTTP/1.1
> Host: ab.text.com
> User-Agent: curl/7.54.0
> Accept: */*
#在加个 -I 请求方法立马变为HEAD
$curl -v -GI -d 'c=wwert' -d 'count=30' ab.text.com
* Trying 10.28.88.199...
* TCP_NODELAY set
* Connected to ab.text.com (10.28.88.199) port 80 (#0)
> HEAD /?c=wwert&count=30 HTTP/1.1
> Host: ab.text.com
> User-Agent: curl/7.54.0
> Accept: */*
>
$curl -i ab.text.com/a.html # -i 只显示响应头信息及访问内容
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Oct 2019 03:53:28 GMT
Content-Type: text/html; charset=utf8
Content-Length: 143
Last-Modified: Tue, 15 Oct 2019 03:59:21 GMT
Connection: keep-alive
ETag: "5da54419-8f"
Accept-Ranges: bytes
#这是a页面
是不是很意外?是不是很惊喜?这就是我的a页面。
tieshan@ytsdeMacBook-Air:~$
$curl -I ab.text.com/a.html
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Oct 2019 03:55:32 GMT
Content-Type: text/html; charset=utf8
Content-Length: 143
Last-Modified: Tue, 15 Oct 2019 03:59:21 GMT
Connection: keep-alive
ETag: "5da54419-8f"
Accept-Ranges: bytes
-K 从某个配置文件中获取curl参数
文件内容示例:以Example开头,以Example结尾
# --- Example file ---
# this is a comment
url = "curl.haxx.se"
output = "curlhere.html"
user-agent = "superagent/1.0"
# and fetch another URL too
url = "curl.haxx.se/docs/manpage.html"
-O
referer = "http://nowhereatall.com/"
# --- End of example file ---
--key 指定私钥,未指定私钥文件,默认以“〜/ .ssh / id_rsa”,“〜/ .ssh / id_dsa”,“ ./ id_rsa”,“ ./ id_dsa”方式读取私钥,存在多个,则使用最后一个。
--key-type
-l 列出FTP目录
$curl -o ssd ab.text.com/a.html #-o 需要在后面加文件名 类似wget下载功能
$ls ssd
ssd
$curl -O ab.text.com/a.html
$ls a.html
a.html
$curl --resolve m.2234sad.com:80:192.168.1.11 http://m.2234sad.com/games/jinbeihaolemenqipai/
#直接获取的是当前网页信息
语法:
curl -T "{file1,file2}" http://www.uploadtothissite.com
示例:
$curl -v -T header.txt ab.text.com/user
$curl -v ab.text.com/a.html
#显示通信信息
* Trying 10.28.88.199...
* TCP_NODELAY set
* Connected to ab.text.com (10.28.88.199) port 80 (#0)
#显示请求头信息
> GET /a.html HTTP/1.1
> Host: ab.text.com
> User-Agent: curl/7.54.0
> Accept: */*
#显示响应信息
< HTTP/1.1 200 OK
< Server: nginx
< Date: Wed, 23 Oct 2019 06:16:13 GMT
< Content-Type: text/html; charset=utf8
< Content-Length: 143
< Last-Modified: Tue, 15 Oct 2019 03:59:21 GMT
< Connection: keep-alive
< ETag: "5da54419-8f"
< Accept-Ranges: bytes
#显示响应体信息
#这是a页面
是不是很意外?是不是很惊喜?这就是我的a页面。
* Connection #0 to host ab.text.com left intact
-w 后面的可以使用的参数
url_effective
http_code 状态码
http_connect
time_total 请求总用时
time_namelookup DNS 域名解析的时候,就是把 https://baidu.com 转换成 ip 地址的过程
time_connect TCP 连接建立的时间,就是三次握手的时间
time_appconnect SSL/SSH 等上层协议建立连接的时间,比如 connect/handshake 的时间
time_redirect 从开始到最后一个请求事务的时间
time_pretransfer 从请求开始到响应开始传输的时间
time_starttransfer 从请求开始到第一个字节将要传输的时间
size_download
size_upload
size_header
size_request
speed_download
speed_upload
content_type
num_connects
num_redirects
ftp_entry_path
#示例 -w意思是将你想要获取的内容显示出来,如果不加-o,将获取整个标头信息
$ curl -sI -w "%{http_code}" -o /dev/null http://www.pc6.com/az/403867.html
200
在7.21.7版本之后可以使用 protocol:// 这种方式代理,跟-x一样的用法,并且默认为http代理
其他几个特殊代理:socks4:// socks4a:// socks5://(这3个是原来的意思) socks5h://(这个特殊些,是指--socks5-hostname)
$ curl -v -x 192.168.1.11:80 http://m.2234sad.com/games/jinbeihaolemenqipai/
* About to connect() to proxy 175.6.2.179 port 80 (#0)
* Trying 192.168.1.11...
* Connected to 192.168.1.11 (192.168.1.11) port 80 (#0)
> GET http://m.2234sad.com/games/jinbeihaolemenqipai/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: m.22234sad.com
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Sun, 29 Sep 2019 01:02:53 GMT
< Content-Type: text/html
< Content-Length: 178
< Connection: keep-alive
< Location: https://m.2234sad.com/games/alogdyan/
<
301 Moved Permanently
301 Moved Permanently
nginx
* Connection #0 to host 192.168.1.11 left intact
$ curl -H "Content-Type:application/json" -XPUT 'http://10.28.88.199:9200/ac/book/1?pretty' -d '{"title":"创始道纪"}'
-z