Native cURL 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 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

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.