- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 PowerShell commandlet Invoke-RestMethod 将图片发布到 URL。这是我的命令:
$usercreds = Get-Credential
$pic = Get-Content \\server\share\pic.jpg
$uri = http://website/sub/destination
Invoke-RestMethod -uri $uri -Method Put -Body $pic -ContentType 'image/jpg' -Credential $usercreds
我收到一个错误:“该文件不是有效的图像文件。”我也尝试使用 Invoke-WebRequest ,结果相同。 Web 服务器不是我们的,他们这边的技术人员说可以使用curl,但我们不知道如何使用,也没有Linux 机器。我有什么遗漏的吗?我可以毫无问题地打开 jpg,因此它没有损坏或任何其他东西。
我尝试了这个,但是服务器对我大喊:Using PowerShell Invoke-RestMethod to POST large binary multipart/form-data
错误代码:
PS C:\Windows\system32> Invoke-WebRequest -uri $uri -Method Put -Body $pic -ContentType 'image/jpg' -Credential $usercreds
Invoke-WebRequest : {"error":{"message":"the file is not a valid image file"},"data":[],"meta":"error"}
At line:1 char:1
+ Invoke-WebRequest -uri $uri -Method Put -Body $pic -ContentType 'imag ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
最佳答案
尝试使用-Infile
参数。 Get-Content
将您的文件解释为字符串数组,但只会把事情搞乱。
$usercreds = Get-Credential
$picPath = "\\server\share\pic.jpg"
$uri = http://website/sub/destination
Invoke-WebRequest -uri $uri -Method Put -Infile $picPath -ContentType 'image/jpg' -Credential $usercreds
关于powershell - 如何使用Invoke-RestMethod上传jpg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42395638/
我有一个REST API,它将返回行。然而, 为什么Invoke-RestMethod -Uri "..." -Method Get | select XXX,YYY仅返回 header ? XXX
我有这段代码: $url = "https://outlook.office365.com/api/v1.0/me/messages" $date = Get-Date -Format "yyyy-M
问题 我很难将 curl 调用转换为Powershell Invoke-RestMethod 调用,因为Powershell并不会发出最多信息的错误消息(如果有的话)。 通话(Ubuntu) toke
我正在尝试创建一个 powershell 脚本来访问 DYN 的 API 并在我使用/测试的 DNS 区域上执行检查/更新。 我正在关注他们的 API 详细信息,这是第一个链接,https://hel
我正在使用 Invoke-RestMethod 从我正在使用的应用程序中获取页面名称。我注意到当我在页面上执行 GET 时,它会像这样返回页面名称 This page â is working 但是实
我们正在使用 Invoke-RestMethod在 PowerShell 脚本中调用 GET具有可变长度运行时的方法端点。有些电话可能会在几秒钟后返回,有些可能需要长达 20 分钟。我们通过 -Tim
使用PowerShell 4.0和Invoke-RestMethod cmdlet。我在使用-OutFile和-PassThru选项时遇到麻烦。 每当我添加-PassThru选项时,都会创建-OutF
我想调用一个传递包含反斜杠字符的参数的 REST API。 API 需要像 api/test// 这样的路由,例如我想传递 domain\login作为 user_name 的值. 我用 PowerS
我正在尝试将文件上传到URL。我尝试了这两种方法: Invoke-RestMethod -Uri $uploadUrl -Method Put -Headers $uploadHdrs -InFile
似乎这个问题已经被提出并得到解答,但到目前为止我遇到的每个解决方案都没有帮助。我正在编写一个 PowerShell 脚本来运行一些 REST API 来获取使用信息。我的脚本在尝试与服务器通信时立即中
Note: this question is here for historical reasons or for users of Powershell -Method GET -ContentT
我正在使用RESTful API,并且使用Firefox RESTClient插件一切都很好。我可以轻松查询API。 但是,当我尝试将相同的API调用插入powershell时不起作用! 我已经尝试了
由于某种原因,这不起作用 Invoke-RestMethod -Uri "http://localhost" -Headers @{"Host"="web.domain.com"} 我收到错误 The
Invoke-RestMethod 遇到了一个非常奇怪的问题。我使用它发送 GET 并在请求中包含 cookie: $getEndpoint = "http://YYYYYYYYYYYYYY/clie
我可以使用Powershell v5中的JIRA rest API。但是,相同的代码在Powershell v3中引发以下错误。 WARNING: Remote Server Response: Th
我正在使用 Invoke-RestMethod -Uri https://... 调用休息服务电话。 .调用结果,位于 JSON , 可以通过管道将数据传输到 Format-Table -Proper
如何使用 Powershell 调用 Azure 身份验证背后的 API?更具体地说,我确实希望这条线能够工作:Invoke-RestMethod -Method Get -Uri 'https://
我正在通过 GET Invoke-RestMethod 从我的应用程序中提取有关提供程序的一些详细信息。目前它正在返回有关提供者的所有详细信息。我只想返回事件状态设置为 True 的提供商的代码。 $
如何使用 Powershell 调用 Azure 身份验证背后的 API?更具体地说,我确实希望这条线能够工作:Invoke-RestMethod -Method Get -Uri 'https://
我正在尝试使用新的 invoke-restmethod cmdlet 来 POST JSON 文件并已成功完成此操作。但是,我没有像使用 CURL 时那样收到网络服务器的响应。对于我想要完成的任务,我
我是一名优秀的程序员,十分优秀!