繁体   English   中英

curl:无法解析主机

[英]curl: could not resolve host

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

第一个:

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 error,当它完成命名所有它无法解决的事情时,我得到一个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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM