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