http - curl PUT 请求响应信息未显示
问题描述
我使用 PUT 请求和 json 请求有效负载构建 curl 请求。我想查看响应标头和有效负载,我在发送请求时添加了 -I arg。我的 curl 请求:
curl -I -X PUT http://localhost:8080/v1/test -H 'X-RequestId:test' -H 'key:test' -H "Content-Type: application/json" -d "{\"status\":\"APPROVE\",\"rules\":null}"
但它向我显示了这样的警告:
Warning: You can only select one HTTP request method! You asked for both POST
Warning: (-d, --data) and HEAD (-I, --head).
解决方案
从curl
手册页:
-I, --head
(HTTP FTP FILE) Fetch the headers only! HTTP-servers feature the
command HEAD which this uses to get nothing but the header of a
document. When used on an FTP or FILE file, curl displays the
file size and last modification time only.
该-I
选项自动使用HEAD
方法发出 http 请求,这就是错误消息的含义。通过使用-d, --data
with-I
不curl
知道使用哪个 http 方法,因为第一个POST
隐式使用方法,第二个使用HEAD
. 这基本上是错误消息所说的:You can only select one HTTP request method!
您可能想要的是小写-i
选项:
-i, --include
Include the HTTP response headers in the output. The HTTP re‐
sponse headers can include things like server name, cookies,
date of the document, HTTP version and more...
To view the request headers, consider the -v, --verbose option.
或者使用-v
选项来查看请求和响应标头。
推荐阅读
- android - 使用 API 28 时不显示 Recyclerview
- pgadmin - pgAdmin 4 在查询生成器上崩溃(在执行查询之前)
- kubernetes - Istio 中的内部服务请求
- ios - 使用 React-Native - 拉动刷新不隐藏在 iOS 上,在 Android 上运行良好
- docker - 如何在 Docker 运行期间运行 shell 脚本
- bash - Bash 脚本 rm 命令在 while 循环中失败
- git - 使用 Git 2.22.1 使用 refs/pull 克隆 GitHub git 存储库(致命:ref 的多个更新)
- php - 如何使用嵌套数组的值创建一个数组?
- haskell - 如何读取功能键等?
- javascript - 当焦点在 contenteditable div 上时删除所有侦听器