0

I'm trying to set the content-type header of my cURL request to application/json.

This is the request I'm using in cmd (I left out the Json-Body):

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

When running this command, cURL is logging the following:

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
<

My REST server is running into an exception because of HTTP 415 Unsupported Media Type.

It seems as if cURL did not make use of my "--header" parameter? Because the log is showing that Content-Type: application/x-www-form-urlencoded was chosen.

I also tried it with the abbreviated parameter "-h".

1 Answers1

0

Seems duplicate question, for more examples, refer here.

How to send a header using a HTTP request through a cURL call?

curl -X POST mockbin.org/request -H "Accept: application/json"
Red Boy
  • 5,429
  • 3
  • 28
  • 41
  • Hi, thanks for your answer, but unfortunately this is not helping me. With Accept-Header I can only determine which kind of content type the client (me) can handle. My problem is that even though I am setting a content-type header, somehow the curl command is not using it. – user10133391 Nov 09 '21 at 13:39
  • Then, problem may be on your server side, are you doing anything behind web server like `apache` or `nginx`? Update your question if so. – Red Boy Nov 09 '21 at 16:51
  • No, problem is not on the server side as I am perfectly able to do requests with Postman and also test curl requests with https://reqbin.com/req/c-woh4qwov/curl-content-type But I need to test with cmd as I need to combine requests but as you can see in the logs in my question, cURL in cmd seems to not change the content-type header... – user10133391 Nov 10 '21 at 09:02