Native cURL-Invoke-WebRequest supported by Powershell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.