[英]Different behavior between PowerShell vs PowerShell ISE
I have a script like this: 我有一个像这样的脚本:
Write-Host "Create RabbitMQ infrastructure..."
$rabbitHost = "http://my.company.com:15672"
$serverPort = 12345
$prefix = "unit"
$user = "test"
$pass = "test"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
$exchanges = ("MyExchange")
$exchanges | foreach {
Write-Host "Create $_"
$body = @{
type = "direct"
durable = "true"
}
$json = $body | ConvertTo-Json
try{
$url = "$rabbitHost/api/exchanges/%2f/$prefix" + "_" + "$serverPort" + "_" + $_
Invoke-RestMethod $url -Body $json -Method Put -Credential $cred -ContentType 'application/json'
} catch {$_.Exception}
}
Everything fine, when I launch it from PowerShell ISE, but when I run it from PowerShell I get an error: 从PowerShell ISE启动它时一切正常,但是从PowerShell运行它时出现错误:
The remote server returned an error: (405) Method Not Allowed.
远程服务器返回错误:(405)不允许使用方法。
I know, that it can be somehow connected with RabbitMq, but I don't see how, because it is just a simple request. 我知道,它可以某种方式与RabbitMq连接,但我不知道如何,因为它只是一个简单的请求。
Can you help me find a root cause of these differences? 您能帮我找到这些差异的根本原因吗?
I wasn't able to reproduce this locally but after some further digging I found this post which refers to another post with more information regarding issues with the %2f URL-encoded character (/). 我无法在本地重现此内容,但经过进一步的挖掘后 ,我发现该帖子是指另一篇帖子 ,其中提供了有关%2f URL编码字符(/)问题的更多信息。
The first post I referenced likely is the issue you were experiencing where the %2f is decoded before the request is made therefore changing the way the URL is interpreted. 我引用的第一篇文章可能是您遇到的问题,在发出请求之前对%2f进行了解码,因此改变了URL的解释方式。 Note that the %2f refers to the default virtual host (see RabbitMQ api documentation).
请注意,%2f是指默认的虚拟主机(请参阅RabbitMQ api文档)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.