加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何在Powershell中使用Invoke-WebRequest重新创建一个有效的CUR

发布时间:2020-12-13 16:57:47 所属栏目:Linux 来源:网络整理
导读:此curl命令按预期工作: curl -H "X-Api-Key:j65k423lj4k2l3fds" ` -X PUT ` -d "alerts_enabled=true" ` https://some/working/file.xml 如何使用Invoke-WebRequest在PS中本机重新创建?我试过了 Invoke-WebRequest -Headers @{"X-Api-Key" = "j65k423lj4k2
此curl命令按预期工作:
curl -H "X-Api-Key:j65k423lj4k2l3fds" `
     -X PUT `
     -d "alerts_enabled=true" `
        https://some/working/file.xml

如何使用Invoke-WebRequest在PS中本机重新创建?我试过了

Invoke-WebRequest -Headers @{"X-Api-Key" = "j65k423lj4k2l3fds"} `
                  -Method PUT `
                  -Body "alerts_enabled=true" `
                  -Uri https://some/working/file.xml

我也尝试为所有参数创建对象(例如$headers = @ {“X-Api-Key”=“Key:j65k423lj4k2l3fds”}并传递-Headers $headers).

谢谢

解决方法

尝试添加参数-ContentType,例如:
Invoke-WebRequest -Headers @{"X-Api-Key" = "j65k423lj4k2l3fds"} -Method PUT `
                  -Body "alerts_enabled=true" -Uri https://some/working/file.xml `
                  -ContentType application/x-www-form-urlencoded

这导致一个看起来像这样的请求(来自Fiddler):

PUT http://some/working/file.xml HTTP/1.1
X-Api-Key: j65k423lj4k2l3fds
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.2; en-US) WindowsPowerShell/5.0.9701.0
Content-Type: application/x-www-form-urlencoded
Host: some
Content-Length: 19
Expect: 100-continue

alerts_enabled=true

为了测试,我将URL从https更改为http.如果这不起作用,请下载Fiddler并在使用curl查看RAW请求时查看不同的内容.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读