1、在 Windows PowerShell 中执行命令:curl -X POST –data,报错:Invoke-WebRequest : 找不到接受实际参数“POST”的位置形式参数。如图1
PS E:/wwwroot/channel-pub-api> curl -X POST --data "access_token=2.00VtCfGEXWOOKE229f72fa42wkzKAE" https://api.weibo.com
/oauth2/get_token_info
Invoke-WebRequest : 找不到与参数名称“X”匹配的参数。
所在位置 行:1 字符: 6
+ curl -X POST --data "access_token=2.00VtCfGEXWOOKE229f72fa42wkzKAE" h ...
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest],ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
2、Invoke-WebRequest 是在 Windows 平台上类似于 cURL 的命令行工具,执行命令:Get-Help Invoke-WebRequest,如图2
PS E:/wwwroot/channel-pub-api> Get-Help Invoke-WebRequest
是否要运行 Update-Help?
Update-Help cmdlet 下载 Windows PowerShell 模块的最新帮助文件,并将其安装在你的计算机上。有关
Update-Help cmdlet 的详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkId=210614。
[Y] 是(Y) [N] 否(N) [S] 暂停(S) [?] 帮助 (默认值为“Y”):
名称
Invoke-WebRequest
摘要
Gets content from a web page on the Internet.
语法
Invoke-WebRequest [-Uri] <Uri> [-Body <Object>] [-Certificate <X509Certificate>] [-CertificateT
[-ContentType <String>] [-Credential <PSCredential>] [-DisableKeepAlive] [-Headers <IDictionary
] [-MaximumRedirection <Int32>] [-Method {Default | Get | Head | Post | Put | Delete | Trace |
tch}] [-OutFile <String>] [-PassThru] [-Proxy <Uri>] [-ProxyCredential <PSCredential>] [-ProxyU
] [-SessionVariable <String>] [-TimeoutSec <Int32>] [-TransferEncoding {chunked | compress | de
ity}] [-UseBasicParsing] [-UseDefaultCredentials] [-UserAgent <String>] [-WebSession <WebReques
arameters>]
说明
The Invoke-WebRequest cmdlet sends HTTP, HTTPS, FTP, and FILE requests to a web page or web ser
response and returns collections of forms, links, images, and other significant HTML elements.
This cmdlet was introduced in Windows PowerShell 3.0.
相关链接
Online Version: http://go.microsoft.com/fwlink/?LinkId=821826
Invoke-RestMethod
ConvertFrom-Json
ConvertTo-Json
备注
若要查看示例,请键入: "get-help Invoke-WebRequest -examples".
有关详细信息,请键入: "get-help Invoke-WebRequest -detailed".
若要获取技术信息,请键入: "get-help Invoke-WebRequest -full".
有关在线帮助,请键入: "get-help Invoke-WebRequest -online"
3、参考帮助文档,调整命令,执行命令,请求成功,如图3
PS E:/wwwroot/channel-pub-api> curl -Uri 'https://api.weibo.com/oauth2/get_token_info' -Body 'access_token=2.00VtCfGEXWO
OKE229f72fa42wkzKAE' -Method 'POST'
StatusCode : 200
StatusDescription : OK
Content : {"uid":3762971921,"appkey":"3815687113","scope":"","create_at":1545898005,"expire_in":44817}
RawContent : HTTP/1.1 200 OK
Connection: keep-alive
Pragma: No-cache
Content-Length: 92
Cache-Control: no-cache
Content-Type: application/json;charset=UTF-8
Date: Fri, 28 Dec 2018 06:33:02 GMT
Expires: Thu,...
Forms : {}
Headers : {[Connection, keep-alive], [Pragma, No-cache], [Content-Length, 92], [Cache-Control, no-cache]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 92
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/251038.html
