如何使用curlpost获取HTTP状态代码
我在Linux上的命令行中使用curl for GET来获取http响应代码。响应主体被打印到标准输出,这很好,但我看不到任何解决方案如何让curl for POST打印HTTP状态代码(200404403等)。这可能吗?要仅获取http\u代码,您可以尝试:如何使用curlpost获取HTTP状态代码,curl,Curl,我在Linux上的命令行中使用curl for GET来获取http响应代码。响应主体被打印到标准输出,这很好,但我看不到任何解决方案如何让curl for POST打印HTTP状态代码(200404403等)。这可能吗?要仅获取http\u代码,您可以尝试: curl -s -o /dev/null --head -w "%{http_code}" -X POST "https://httpbin.org/post" 你可以像这样阅读/记忆它: -s静默模式 -o将输出写入/dev/nul
curl -s -o /dev/null --head -w "%{http_code}" -X POST "https://httpbin.org/post"
你可以像这样阅读/记忆它:
静默模式-s
将输出写入/dev/null-o
获取标题 只有--head
写出http状态代码-w“%{http\u code}”
curl -I -X POST "https://httpbin.org/post"
它将返回如下内容:
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Thu, 28 Mar 2019 20:12:01 GMT
Server: nginx
Content-Length: 294
Connection: keep-alive
如何在windows命令提示符下使用此命令我尝试了命令
curl-i-s-w%{http_code}server:8080/page/
,它抛出curl:no-URL指定代码>我猜您需要在目标URL中指定协议,如下所示:curl-I-s-w%{http_code}
curl -X POST --write-out %{http_code} --silent --output /dev/null --data "{your_json_input}}" -H 'Content-Type:application/json' http://your_url