cURL for Windows: how can I send multiple line com

2020-05-26 10:26发布

I am learning to use cURL and I need to run this in a console:

curl -XGET localhost:9200/library/book/_search?pretty=true -d {
    "query" : {
        "query_string" : { "query" : "title:crime" }
    }
}

But this is a multi-line command. How can I handle it to send a complete command?

Note that I understand I can put the content after -d in a file to run this command.

标签: curl libcurl
3条回答
放荡不羁爱自由
2楼-- · 2020-05-26 10:41

Sometime I have to use windows, try something like this :

curl -XPOST http://localhost:9200/_search -d^
"{^
    \"query\": {^
        \"query_string\": {^
            \"query\": \"year:2003\"^
        }^
    }^
}"

^ to extend a command to next line and
\" to escape " on the json

查看更多
Melony?
3楼-- · 2020-05-26 10:50

Install Git for windows. Use git bash to run the curl commands.

查看更多
孤傲高冷的网名
4楼-- · 2020-05-26 11:01

I didn't find any way so far to send command spanning multiple using curl on windows. However, I was able to find a way to get the task done. Below is how I would rewrite the command you are trying to achieve

curl -XGET localhost:9200/library/book/_search?pretty=true -d "{ \"query\" : { \"query_string\" : { \"query\" : \"title:crime\" }  } }"

Just make sure the /library/book/ is right index name.

Hoping to hear back if you are able to make it

查看更多
登录 后发表回答