CURL (clients for URL) is a common command line tool used to transmit data based on URLs. It supports HTTP, HTTPS, FTP, and other protocols. In fact, on Windows, a similar command Invoke-WebRequest has been added since Powershell 3.0. The following Help information is displayed when you execute Get-Help Invoke-WebRequest. Take a look at the ALIASES section. The curl is in the column. That is to say, you can directly use curl as the command name!
The syntax of Invoke-WebRequest is different from that of cURL. However, if cURL is used, it is very easy to convert to Invoke-WebRequest, here are several examples of using cURL and Invoke-WebRequest to operate ElasticSearch (curlw.curl.exe command, Invoke-WebRequest is the implementation in Powershell ):
CURL-XGET 'localhost: 9200/library/book/_ search' Invoke-WebRequest http: // localhost: 9200/library/book/_ search
-MethodGET (GET operation can also be omitted) cURL-XPOST 'localhost: 9200/library 'Invoke-WebRequest http: // localhost: 9200/library
-MethodPOST cURL-XPUT 'localhost: 9200/library/book/_ ing '-d @ mapping. jsonInvoke-WebRequest http: // localhost: 9200/library/book/_ mapping-Method PUT
-InFileMapping. json cURL-XPOST 'localhost: 9200/blog/article'-d' {"title": "ElasticSearch"} 'invoke-WebRequesthttp: // localhost: 9200/blog/article-Method POST
-Body'{"Title": "ElasticSearch"} 'curl-xget' localhost: 9200/library/book/_ search? Q = title: crime & pretty = true 'invoke-WebRequesthttp: // localhost: 9200/library/book/_ search? Q = title: ElasticSearch "&" pretty = true
-OutFileResponse.txt cURL-XPOST 'localhost: 9200/library/book/_ search? Pretty = true '-d' {"query": {"term": {"title": "wp8.1" }}' Invoke-WebRequesthttp: // localhost: 9200/library/book/_ search? Pretty = true-Method POST
-Body'{"Query": {"term": {"title": "wp8.1" }}' cURL-XPOST' localhost: 9200/library/book/_ search? Pretty = true '-d' {"query": {"terms": {"tags": ["surface", "wp8.1"], "minimum_match ": 2} 'invoke-WebRequesthttp: // localhost: 9200/library/book/_ search? Pretty = true-Method POST-Body '{"query": {"terms": {"tags": ["surface", "wp8.1"], "minimum_match ": 2 }}'too many attempts have been made too many