简体   繁体   English

curl:无法解析主机

[英]curl: could not resolve host

I am trying to send a POST/PUT requests with CMD (command prompt in windows 10) using these commands:我正在尝试使用以下命令发送带有 CMD 的 POST/PUT 请求(windows 10 中的命令提示符):

1st:第一个:

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

2nd:第二:

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

and using these commands I am getting a curl: could not resolve error, and when its done naming everything it couldn't resolve I get a server error status 500 I don't understand why its not working cause I tried these commands and they seemed to work before and they don't.并使用这些命令,我得到一个curl: could not resolve error,当它完成命名所有它无法解决的事情时,我得到一个server error status 500我不明白为什么它不起作用,因为我尝试了这些命令,他们似乎以前工作,他们没有。

(I thought I had an error in my code and I tried the http request instead of curl and it worked fine with no problem getting the 200 OK status.). (我以为我的代码有错误,我尝试了 http 请求而不是 curl 并且它运行良好,没有问题获得200 OK状态。)。

在此处输入图像描述

Watch out for double quotes insides double quotes:注意双引号内的双引号:

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

If NOT on Windows, the answer above by @Necklondon with the single quotes should work.如果不在 Windows 上,@Necklondon 上面带有单引号的答案应该有效。

If on Windows, however, you'll need to escape the double quotes within the JSON string.但是,如果在 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

In addition, to illustrate how much simpler the CURL command becomes when using a separate file for your JSON...此外,为了说明在为 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