Robert Strauch
Robert Strauch

Reputation: 12906

cURL POST request with bearer token results in "Could not resolve host: POST"

I'm issuing the following command in zsh to send a POST request with a bearer token.

curl -o -X POST -H "Authorization: Bearer ${TOKEN}" http://localhost:8090/services/item/0

The output I get is the following:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: POST

Update 1

I posted a wrong command which I have corrected now. This is what I'm issuing:

curl -X POST -H "Authorization: Bearer ${TOKEN}" http://localhost:8090/services/item/0

I discovered that the behavior is probably related to running the command in a ZSH. When using Bash the call works fine.

Upvotes: 0

Views: 1554

Answers (2)

Daniel Stenberg
Daniel Stenberg

Reputation: 58164

The parameter that follows -o is a file name. Your command line begins with:

curl -o -X POST

... which then means that it will save the output to a file named -X. Then the following word (POST) will be treated as a URL since it doesn't start with a dash...

Using that URL (or host name rather) then causes this error:

Could not resolve host: POST

... because curl fails to resolve that host name. It seems there's no host in your network with that name!

Upvotes: 2

Dmitry Leiko
Dmitry Leiko

Reputation: 4412

I check must work:

curl -H "Authorization: Bearer ${TOKEN}" http://localhost:8090/services/item/0

Or:

curl -H "Authorization: Bearer ${TOKEN}" http://localhost:8090/services/item/0 -o output.txt

Upvotes: 0

Related Questions