Powershell原生支持的cURL
来源:互联网 发布:chrome js 拷贝 编辑:程序博客网 时间:2024/05/29 05:11
Powershell原生支持的cURL - Invoke-WebRequest
http://www.aichengxu.com/shell/2527399.htm在windows的powershell下,执行elasticsearch的curl的如下命令时,总提示错误,
PS C:\Users\xuewen.liang> curl -XPUT 'localhost:9200/customer?pretty'Invoke-WebRequest : A parameter cannot be found that matches parameter name 'XPUT'.At line:1 char:6+ curl -XPUT 'localhost:9200/customer?pretty'+ ~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommandPS C:\Users\xuewen.liang> curl -XPUT 'http://localhost:9200/customer?pretty'Invoke-WebRequest : A parameter cannot be found that matches parameter name 'XPUT'.At line:1 char:6+ curl -XPUT 'http://localhost:9200/customer?pretty'+ ~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
原因如下,是应为要替换成power里的Invoke-WebRequest命令的相应写法:
cURL (clients
for URL) 是一款常用的命令行工具,它被用于基于URL传输数据,它支持HTTP, HTTPS,FTP等协议。其实,在Windows平台上,从Powershell 3.0开始也增加了一个类似的命令
Invoke-WebRequest, 执行 Get-Help Invoke-WebRequest 会看到下面的帮助信息。注意看一下其中的ALIASES部分,curl赫然在列。也就是说,你可以直接使用curl作为命令名字,呵呵!
Invoke-WebRequest的语法与cURL有所不同,但如果会用cURL,转换到使用Invoke-WebRequest非常简单,
下面举几个使用cURL和Invoke-WebRequest操作ElasticSearch的例子
(cURL表示cURL.exe命令,Invoke-WebRequest则是Powershell中的的实现):
cURL -XGET 'localhost:9200/library/book/_search'
Invoke-WebRequest http://localhost:9200/library/book/_search -Method GET (GET操也作可以省略)
cURL -XPOST 'localhost:9200/library'
Invoke-WebRequest http://localhost:9200/library -Method POST
cURL -XPUT 'localhost:9200/library/book/_mapping' -d@mapping.json
Invoke-WebRequest http://localhost:9200/library/book/_mapping -Method PUT -InFile mapping.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 -OutFile response.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}}}'
curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.enable": none}}'
Invoke-RestMethodhttp://localhost:9200/_cluster/settings -Method PUT -Body '{"transient":{"cluster.routing.allocation.enable":
"none"}}'
Invoke-RestMethod http://localhost:9200/_cluster/settings -Method
PUT -Body '{"transient":{"cluster.routing.allocation.cluster_concurrent_rebalance": "6"}}'
除了Invoke-WebRequest,Powershell 3.0起还提供了Invoke-RestMethod 命令,它专门用于向RESTful web服务发送HTTP和HTTPS数据。
两个命令很相似,但也有不同,具体的不同可以参见《WidnowsPowerShell》一书
- Powershell原生支持的cURL
- Powershell原生支持的cURL - Invoke-WebRequest
- php添加curl 的支持
- 编译支持https的curl
- Ubuntu的php支持curl
- android 原生支持的音频格式
- c++原生的unicode支持
- PowerShell只支持.NET2.0的问题
- debian开启php的curl支持
- CURL支持HTTPS,FTPS等的配置
- 封装的curl 支持get post header
- 原生支持Java应用的芯片出现
- Mac原生字典支持的词典
- (一)JDK原生支持的WebService
- Validation JSR-303原生支持的限制
- 优化Hybrid app的原生支持
- PHP对观察者模式的原生支持
- SpringMvc对Servlet原生API的支持
- 在共享内存实现 Redis(上)
- HDU 5783 Divide the Sequence——贪心
- shiro中的请求参数
- android UiAutomator生成测试报告的基本方法封装
- BZOJ4538 网络 [树链剖分]
- Powershell原生支持的cURL
- java基础——java api各包概述
- windows重启系统
- systemd详解
- POJ4081树的转换以及deque iterator not dereferencable 问题
- 从硬件到软件,亲自动手组建家庭多媒体文件系统
- html——登录后台、验证码
- 学习笔记-python数据分析-环境配置
- Android 常用图标尺寸及设计规范汇总