[英]cURL - Setting Content-Type Header is not working?
我正在嘗試將 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 Unsupported Media Type,我的 REST 服務器遇到異常。
好像 cURL 沒有使用我的“--header”參數? 因為日志顯示選擇了 Content-Type: application/x-www-form-urlencoded。
我還嘗試使用縮寫參數“-h”。
似乎是重復的問題,有關更多示例,請參閱此處。
curl -X POST mockbin.org/request -H "Accept: application/json"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.