可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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/"}"
回答1:
In my case, putting space after colon was wrong.
# Not work curl -H Content-Type: application/json ~ # OK curl -H Content-Type:application/json ~
回答2:
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.
回答3:
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