http 常用工具 curl 使用介绍

http 客户端命令行工具 curl

如何安装: 

(ubuntu)

 apt-get  install -y curl  

最简单方式: (get)

curl http://127.0.0.1:8080
<html>
<head>
  <title>libevent http server </title>
</head>
<body>
  <h1>libevent http server start success</h1>
</body>
</html>

加上 -v  参数可以返回 header 的内容

curl -v  http://127.0.0.1:8080
* Rebuilt URL to: http://127.0.0.1:8080/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Wed, 05 May 2021 08:26:52 GMT
< Content-Length: 130
< Content-Type: text/html; charset=ISO-8859-1
< 
<html>
<head>
  <title>libevent http server </title>
</head>
<body>
  <h1>libevent http server start success</h1>
</body>
</html>
* Connection #0 to host 127.0.0.1 left intact

--data-binary 把本地文件取出来上传:(POST请求)

 curl --data-binary @./go.zip -v  http://127.0.0.1:8080  

Content-Length: 156004847 会显示上传的文件大小 

curl --data-binary @./go.zip -v  http://127.0.0.1:8080
* Rebuilt URL to: http://127.0.0.1:8080/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> POST / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Length: 156004847
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< Date: Wed, 05 May 2021 08:30:09 GMT
< Content-Length: 130
< Content-Type: text/html; charset=ISO-8859-1
< 
<html>
<head>
  <title>libevent http server </title>
</head>
<body>
  <h1>libevent http server start success</h1>
</body>
</html>
* Connection #0 to host 127.0.0.1 left intact

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值