curl: 无法解析主机

curl: could not resolve host

我正在尝试使用以下命令通过 CMD(windows 10 中的命令提示符)发送 POST/PUT 请求:

第一名:

curl -iX PUT -H "Content-Type: application/json" -d \"{\"name\": \"test number 1\", \"description\": \"a website test \", \"category\": \"test\", \"release_date\": \"2017-10-08T01:01:00.776594Z\"}\" localhost:8000/home/search/3

第二名:

curl -iX PUT -H "Content-Type: application/json" -d "{"name": "test number 1", "description": "A website test", "category": "test", "release_date": "2017-10-08T01:01:00.776594Z"}" localhost:8000/home/search/3

并使用这些命令我收到 curl: could not resolve 错误,当它完成命名所有它无法解决的问题时我收到 server error status 500 我不明白为什么它不起作用,因为我尝试过这些命令,它们以前似乎可以工作,但现在没有。

(我以为我的代码有错误,我尝试了 http 请求而不是 curl,它工作正常,没有问题获得 200 OK 状态。)。

注意双引号内的双引号:

curl -iX PUT -H "Content-Type: application/json" -d '{"name": "test number 1", "description": "A website test", "category": "test", "release_date": "2017-10-08T01:01:00.776594Z"}' localhost:8000/home/search/3

如果不在 Windows 上,@Necklondon 上面用单引号给出的答案应该有效。

但是,如果在 Windows 上,您需要转义 JSON 字符串中的双引号。

curl -iX PUT -H "Content-Type: application/json" -d "{""name"": ""test number 1"",""description"": ""A website test"",""category"": ""test"",""release_date"": ""2017-10-08T01:01:00.776594Z""}" http://localhost:8000/home/search/3

此外,为了说明当为您的 JSON...

使用单独的文件时,CURL 命令变得多么简单
C:\Users\...\Desktop>TYPE somefile.json
{
    "name": "test number 1",
    "description": "A website test",
    "category": "test",
    "release_date": "2017-10-08T01:01:00.776594Z"
}

C:\Users\...\Desktop>curl -iX PUT -H "Content-Type: application/json" --data-binary @somefile.json http://localhost:8000/home/search/3