簡體   English   中英

PowerShell與PowerShell ISE之間的不同行為

[英]Different behavior between PowerShell vs PowerShell ISE

我有一個像這樣的腳本:

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}
}

從PowerShell ISE啟動它時一切正常,但是從PowerShell運行它時出現錯誤:

遠程服務器返回錯誤:(405)不允許使用方法。

我知道,它可以某種方式與RabbitMq連接,但我不知道如何,因為它只是一個簡單的請求。

您能幫我找到這些差異的根本原因嗎?

我無法在本地重現此內容,但經過進一步的挖掘 ,我發現該帖子是指另一篇帖子 ,其中提供了有關%2f URL編碼字符(/)問題的更多信息。

我引用的第一篇文章可能是您遇到的問題,在發出請求之前對%2f進行了解碼,因此改變了URL的解釋方式。 請注意,%2f是指默認的虛擬主機(請參閱RabbitMQ api文檔)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM