没有不值得去解决的问题,也没有不值得去学习的技术!

Analyze and Resolve the “Invoke-WebRequest: A positional parameter cannot be found that accepts argument ‘POST’” Error When Running curl -X POST –data in Windows PowerShell

Running the command curl -X POST --data in Windows PowerShell results in the error: Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'POST'.

1. When running the command `curl -X POST –data` in Windows PowerShell, an error occurs: Invoke-WebRequest : A positional parameter cannot be found that accepts argument ‘POST’. As shown in Figure 1.

Running the command curl -X POST --data in Windows PowerShell results in the error: Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'POST'.
Figure 1
Plaintext
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
    + Fully QualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand


2. Invoke-WebRequest is a command-line tool on the Windows platform similar to cURL. Run the command: Get-Help Invoke-WebRequest, as shown in Figure 2.

Invoke-WebRequest is a command-line tool on the Windows platform similar to cURL. Run the command: Get-Help Invoke-WebRequest
Figure 2
Plaintext
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]  [-Body ] [-Certificate ] [-CertificateT
    [-ContentType ] [-Credential ] [-DisableKeepAlive] [-Headers ] [-Method {Default | Get | Head | Post | Put | Delete | Trace |
    tch}] [-OutFile ] [-PassThru] [-Proxy ] [-ProxyCredential ] [-ProxyU
    ] [-SessionVariable ] [-TimeoutSec ] [-TransferEncoding {chunked | compress | de
    ity}] [-UseBasicParsing] [-UseDefaultCredentials] [-UserAgent ] [-WebSession ]


说明
    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. Referring to the help documentation, I adjusted the command and executed it. The request was successful, as shown in Figure 3.

Referring to the help documentation, adjust the command, execute the command, and the request succeeds
Figure 3
Plaintext

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



关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系