簡體   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