curl 不打印返回值信息

curl About 1,964 words

需求

curl不打印返回值信息,只打印HTTP请求头、返回头、连接信息等。

为了排查Chrome开发者工具network选项卡中status显示(failed),具体内容是:net::ERR_INCOMPLETE_CHUNKED_ENCODING

-o

使用curl-o参数,o表示output输出到指定文件。

只需输出到/dev/null黑洞中即可。

命令

curl -vv -o /dev/null http://localhost:8081/test

输出

 curl -vv -o /dev/null http://localhost:8081/test
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1:8081...
* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET /test HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 29 Jun 2023 05:50:29 GMT
<
{ [7862 bytes data]
* transfer closed with outstanding read data remaining
100 12634    0 12634    0     0   341k      0 --:--:-- --:--:-- --:--:--  397k
* Closing connection 0
curl: (18) transfer closed with outstanding read data remaining

-s:不显示进度信息

❯ curl -vv -s -o /dev/null http://localhost:8081/test
*   Trying 127.0.0.1:8081...
* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET /test HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 29 Jun 2023 05:59:30 GMT
<
{ [7862 bytes data]
* transfer closed with outstanding read data remaining
* Closing connection 0
Views: 1,589 · Posted: 2023-09-01

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh