我正在尝试将消息(“mymessage”)发布到ActiveMQ队列(“myqueue”)。在Powershell v3 +中,使用Invoke-WebRequest非常简单。不幸的是,我坚持使用v2。据我所知,这是我需要在v2中复制的Powershell v3中的代码:
$uri = "http://ACTIVEMQ-SERVER:8161/admin/sendMessage.action"
$r = Invoke-WebRequest http://ACTIVEMQ-SERVER:8161/admin/send.jsp -SessionVariable amq
$form = $r.Forms[0]
$form.fields["JMSDestination"] = "myqueue"
$form.fields["JMSPersistent"] = "true"
$form.fields["JMSText"] = "mymessage"
$r = Invoke-WebRequest -Uri $uri -WebSession $amq -Method Post -Body $form.Fields
我目前的尝试是这样的:
$uri1 = [System.Uri]'http://ACTIVEMQ-SERVER:8161/admin/sendMessage.action'
$uri2 = [System.Uri]'http://ACTIVEMQ-SERVER:8161/admin/send.jsp'
$password = ConvertTo-SecureString 'mypassword' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential('myusername',$password)
$request = [System.Net.WebRequest]::Create($uri2)
$request.method = "GET"
$request.Credentials = $credential
如你所见,我没有取得多大进展。我对Powershell很新,尤其是它的.NET方面。任何帮助将不胜感激。