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 operations 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. json
- Invoke-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 }}}'
In addition to Invoke-WebRequest, Powershell also provides the Invoke-RestMethod command from 3.0 onwards, which is used to send HTTP and HTTPS data to RESTful web Services. The two commands are very similar, but they are also different. For specific differences, see Widnows PowerShell.
When there are already too many other users