curl工具使用方法

1.curl I 查看HTTP 响应头信息

~ # curl -I "www.baidu.com"
HTTP/1.1 200 OK
Server: bfe/1.0.8.18
Date: Wed, 04 Sep 2019 06:10:22 GMT
Content-Type: text/html
Content-Length: 277
Last-Modified: Mon, 13 Jun 2016 02:50:36 GMT
Connection: Keep-Alive
ETag: "575e1f7c-115"
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Pragma: no-cache
Accept-Ranges: bytes

~ # 

2. HTTP 响应头的信息

(1).  HTTP 返回码:

1xx:client的请求server已经接收,正在处理
2xx:成功  表示 client请求,server端已经接收、理解并处理
3xx:client 请求被重定向其他的server【其他的URL】
4xx:表示client请求不正确,server不能识别
5xx:server端服务不正常
(2). Cache-Control:

web 站点对缓存的设置;

no-cache:表示server 不允许client 设置缓存;client每次请求都需要请求后端的服务
max-age:server设置页面的缓存时间;单位是秒  即:1个小时内此client再访问 www.taobao.com 用刚才的缓存;不在访问后台服务器
private must-revalidate
(3). Connection:

server 是否支持长连接;如果keep-alive 说明web的server 支持长连接。

但是TCP 的长连接是双向的;必须是client和server 都支持长连接;才可以建立长连接。

一般client 【浏览器】都是默认支持长连接;所以只要sever端支持长连接;就可以建立长连接。

3. curl 发送Get/Post 请求

1). get 请求

我们平时用的最多的就是curl 不加任何的参数,其实这样就是get请求;把参数都放在http://xx 后面

curl "http://baidu.com/name=shuming&age=20

2). post 请求

curl -d "name=shuming&age=20" "http://baidu.com"

3). 上传文件

curl -F 'csl=@/home/xxxx/xxx.csl' -F 'tag=xxx' -F 'category=full' "http://ip:9000/api/jobs"

原创文章 96 获赞 48 访问量 6万+

猜你喜欢

转载自blog.csdn.net/wteruiycbqqvwt/article/details/100537966