124

Getting url: (6) Could not resolve host: application error after this command :

curl -i -H 'Content-Type: application/json' -d '{"Code":"FR","Name":"France"}' http://127.0.0.1:8080/countries

Full error log:

curl: (6) Could not resolve host: application
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json; charset=utf-8
X-Powered-By: go-json-rest
Date: Sat, 02 Apr 2016 05:31:20 GMT
Content-Length: 73

{
"Error": "Bad Content-Type or charset, expected 'application/json'"
}

What's wrong with this command?

Edit:

I solved my problem editing like this in windows : "{/"Code/":/"FR/"}"

Yeahia2508
  • 7,526
  • 14
  • 42
  • 71

10 Answers10

223

In my case, putting space after colon was wrong.

# Not work
curl -H Content-Type: application/json ~
# OK
curl -H Content-Type:application/json ~
kujiy
  • 5,833
  • 1
  • 29
  • 35
  • This explains why none of my Surveymonkey API requests with json data were working. Thank you! – ChrisFNZ Oct 27 '20 at 03:18
  • 15
    On Windows I was also able to fix it by using `"` instead of `'`. Not work: `curl -H 'Accept: application/json'`. Work: `curl -H "Accept: application/json"`. – serg06 Apr 02 '21 at 00:25
  • 1
    It seems like using `'`single quotes`'` on Windows just causes all kinds of problems which are difficult to diagnose because the errors often make no sense. Using `-v` should clear things up. – Christopher Schultz Feb 15 '22 at 15:48
21

It's treating the string application as your URL.
This means your shell isn't parsing the command correctly.
My guess is that you copied the string from somewhere, and that when you pasted it, you got some characters that looked like regular quotes, but weren't.
Try retyping the command; you'll only get valid characters from your keyboard. I bet you'll get a much different result from what looks like the same query. As this is probably a shell problem and not a 'curl' problem (you didn't build cURL yourself from source, did you?), it might be good to mention whether you're on Linux/Windows/etc.

LinuxDisciple
  • 2,289
  • 16
  • 19
19

I replaced all the single quotes ['] to double quotes ["] and then it worked perfectly. Thanks for the input by @LogicalKip.

Dharman
  • 30,962
  • 25
  • 85
  • 135
zaffar
  • 679
  • 6
  • 13
15

Example for Slack.... (use your own web address you generate there)...

curl -X POST -H "Content-type:application/json" --data "{\"text\":\"A New Program Has Just Been Posted!!!\"}" https://hooks.slack.com/services/T7M0PFD42/BAA6NK48Y/123123123123123

Cyphire
  • 521
  • 1
  • 5
  • 8
9

I was getting this error too. I resolved it by installing: https://git-scm.com/

and running the command from the Git Bash window.

heyitsmyusername
  • 631
  • 1
  • 8
  • 21
6

For my issue using curl on Windows 10 with the environment variable already setup,

curl -X POST -H "Content-Type:application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\":[],\"id\":83}" https://some-node-url.com

I needed to replace all single quotes ' with double quotes "

even though the example for the blockchain I was trying to curl to had a single quote.

And also add \ in front of all the double quotes inside the param brackets {}

DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
1

In my case, it was a missing line break that added unneeded parameters due to a bad copy and paste.

I followed a guide at https://pytorch.org/docs/stable/notes/windows.html#include-optional-components which looks like this when you copy it right here without any editing:

REM Make sure you have 7z and curl installed.

REM Download MKL files

curl https://s3.amazonaws.com/ossci-windows/mkl_2020.0.166.7z -k -O 7z x -aoa mkl_2020.0.166.7z -omkl

Output:

C:\Users\Admin>curl "https://s3.amazonaws.com/ossci-windows/mkl_2020.0.166.7z" -k -O 7z x
-aoa mkl_2020.0.166.7z -omkl   
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed 
100  103M  100  103M  0     0  5063k      0  0:00:21  0:00:21 --:--:-- 5629k
0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0curl: (6) Could not resolve host: 7z
0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0curl: (6) Could not resolve host: x 
curl: (6) Could not resolve host: mkl_2020.0.166.7z

There is actually a line break before "7z", with "7z" as the executable (and before, in addition to adding curl to your user PATH, you need to add 7z to the user PATH as well, for example with setx PATH "%PATH%;C:\Program Files\7-Zip\"):

REM Download MKL files

curl https://s3.amazonaws.com/ossci-windows/mkl_2020.0.166.7z -k -O

7z x -aoa mkl_2020.0.166.7z -omkl

questionto42
  • 7,175
  • 4
  • 57
  • 90
1

In my case, I copied the curl command from Confluence to TextEdit. After spending almost an hour, and trying to paste the command in different text editors in order to sanitize, finally, PyCharm helped me (IntelliJ should help too)

After pasting it in PyCharm I got to see the error

Non-breaking spaces

After removing these "NBSP" (non-breaking spaces), the command started running fine.

Ganesh Satpute
  • 3,664
  • 6
  • 41
  • 78
1

In ubuntu like system this mainly occurs when we don’t have nameservers in the /etc/resolv.conf

So, we added the following line in the file.

nameserver 8.8.8.8

Then, this fixed the error and the host started resolving.

muhive
  • 1,879
  • 14
  • 20
  • in my rasperry pi I was able to solve the problem using your suggestion, however, the issue pops up frequently. This resolf.conf file frequently missing this line `nameserver 8.8.8.8` . Do you know how to solve the issue forever? – Arseniy Sleptsov Nov 03 '22 at 16:59
0

Windows consoles usually doesnt interpret double quotes correctly in a JSON array, so you can solve it adding a slash / before double quotes.

enrique-es
  • 41
  • 1
  • 5