cURL-设置内容类型标题不起作用



我正在尝试将cURL请求的内容类型标头设置为application/json。

这是我在cmd中使用的请求(我省略了Json Body(:

curl -v -X POST http://localhost:40071/api/Sale --header 'Content-Type: application/json' -d '{[Json Body]}'

运行此命令时,cURL会记录以下内容:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:40071...
* Connected to localhost (127.0.0.1) port 40071 (#0)
> POST /api/Sale HTTP/1.1
> Host: localhost:40071
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 332
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 09 Nov 2021 11:18:33 GMT
< Content-length: 0
<

由于HTTP 415不支持的媒体类型,我的REST服务器遇到异常。

似乎cURL没有利用我的"--标题";参数因为日志显示选择了内容类型:application/x-www-form-urlencoded。

我还用缩写参数"-h";。

似乎是重复的问题,有关更多示例,请参阅此处。

如何通过cURL调用使用HTTP请求发送标头?

curl -X POST mockbin.org/request -H "Accept: application/json"

最新更新