我正在使用带有 bash shell 的 Mac 10.9.5。我正在尝试通过 curl 提交请求,但是当我尝试设置内容类型标头时,我不断收到错误消息。下面我试试
davea$ curl -v -o -H "Content-Type: application/json" -X POST -d '{"username”:”username”,”password”:”password”}’ http://localhost:8080/myproject/login
Run Code Online (Sandbox Code Playgroud)
但是 curl 会吐出“curl: (6) 无法解析主机 'Content-Type'”错误。下面是完整的输出:
* getaddrinfo(3) failed for Content-Type:80
* Couldn't resolve host 'Content-Type'
* Closing connection 0
curl: (6) Couldn't resolve host 'Content-Type'
* Trying ::1...
* Connected to localhost (::1) port 8080 (#1)
> POST /myproject/login HTTP/1.1
> User-Agent: curl/7.40.0
> Host: localhost:8080
> Accept: */*
> Content-Length: 40
> Content-Type: application/x-www-form-urlencoded
>
* upload completely …
Run Code Online (Sandbox Code Playgroud)