隐藏卷曲输出

Rja*_*ack 304 curl

我正在发出一个 curl 请求,它在控制台中显示一个 html 输出,如下所示

<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/domain/public_html/wp-content/themes/explicit/functions/ajax.php:87) in <b>/home/domain/public_html/wp-content/themes/explicit/functions/ajax.php</b> on line <b>149</b><br />......
Run Code Online (Sandbox Code Playgroud)

等等

我需要在运行 CURL 请求时隐藏这些输出,尝试像这样运行 CURL

curl -s 'http://example.com'
Run Code Online (Sandbox Code Playgroud)

但它仍然显示输出,如何隐藏输出?

谢谢

Flo*_*elf 446

man curl

-s, --silent 静默或安静模式。不要显示进度表或错误消息。使 Curl 静音。它仍然会输出您要求的数据,甚至可能输出到终端/标准输出, 除非您重定向它

因此,如果您不想要任何输出,请使用:

curl -s 'http://example.com' > /dev/null
Run Code Online (Sandbox Code Playgroud)

  • 如果你只想要错误添加 -S 标志 curl -s -S 'http://example.com' &gt; /dev/null (34认同)
  • 请注意,您不能执行“curl -o /dev/null”;它会抛出一个写入错误。 (3认同)
  • @KeithTyler `curl https://www.google.com -o /dev/null` 对我来说成功而没有错误。我正在使用 `curl-7.58.0`。 (2认同)

yeg*_*256 110

这个对我来说看起来更优雅:

curl --silent --output /dev/null http://example.com
Run Code Online (Sandbox Code Playgroud)

另外,如果您想查看 HTTP 代码:

curl --write-out '%{http_code}' --silent --output /dev/null http://example.com
Run Code Online (Sandbox Code Playgroud)

完整文档在这里

  • 如果您仍然希望显示错误,您也可以添加 `--show-error` 参数。 (16认同)