0

I am learning Go, and am currently working through this tutorial. When I run the command to test that POST is handled correctly, I get an error message. I cast the body to a string in the course of my debugging, and as best I can tell only part of the json body is being properly included under the data flag. I made the same POST request via Postman, and it worked perfectly. Running the latest version of curl.

Error:

HTTP/1.1 200 OK
Date: Wed, 26 Jul 2023 22:34:49 GMT
Content-Length: 0

curl: (6) Could not resolve host: Modern
curl: (6) Could not resolve host: Sound
curl: (6) Could not resolve host: of
curl: (6) Could not resolve host: Betty
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 20:
Carter,price: 49.99}
         ^

Curl command:

curl http://localhost:8080/albums --include --header "Content-Type: application/json" --request "POST" --data '{"id": "4","title": "The Modern Sound of Betty Carter","artist": "Betty Carter","price": 49.99}'
Thoven
  • 11
  • 1
  • I can't reproduce this with the command you show and a dummy server using netcat that just listens to port 8080. – Benjamin W. Jul 26 '23 at 23:24
  • 2
    Please show the full curl command. The error `curl: (6) Could not resolve host: Modern` implies that part of the response is treated as URL – Pak Uula Jul 26 '23 at 23:52
  • 2
    This has nothing to do with go. The command line is interpreted not in the way you've expected because the quoting you've used is correct for some UNIX shell but not for Windows. That's why the single argument you've intended to be the body for POST is actually treated as multiple arguments which are interpreted as URLs. See [curl: (6) Could not resolve host: application](https://stackoverflow.com/questions/36361572/curl-6-could-not-resolve-host-application) – Steffen Ullrich Jul 27 '23 at 05:27

0 Answers0