尝试在Powershell中运行XML字符串

时间:2018-06-21 15:13:31

标签: powershell

尝试使用PowerShell运行以下内容。

使用以下URL:

https://uat-somesite.com/folder/broker?ACTION=GETPREFS&REQUEST=<?xml%20version='1.0'%20encoding='utf-8'?><PreferencesRequest><IPAddress>10.10.10.10</IPAddress><Name>MACHINE-NAME</Name><PAN>0</PAN></PreferencesRequest>

放入PowerShell:

Invoke-WebRequest https://uat-somesite.com/folder/broker?ACTION=GETPREFS%26REQUEST=<?xml%20version='1.0'%20encoding='utf-8'?><PreferencesRequest><IPAddress>10.10.10.10</IPAddress><Name>MACHINE-NAME</Name><PAN>0</PAN></PreferencesRequest>

并得到结果消息:

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a 
send.
At line:1 char:1
+ Invoke-WebRequest https://uat-somesite.com/folder/broker% ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [In 
   voke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.Invo 
   keWebRequestCommand

XML字符串为:

<?xml%20version='1.0'%20encoding='utf-8'?>
<PreferencesRequest>
<IPAddress>10.10.10.10</IPAddress>
<Name>MACHINE-NAME</Name><PAN>0</PAN></PreferencesRequest>

我可以将以下内容粘贴到我的浏览器中。

https://uat-somesite.com/folder/broker?ACTION=GETPREFS&REQUEST=%3C?xml%20version=%271.0%27%20encoding=%27utf-8%27?%3E%3CPreferencesRequest%3E%3CIPAddress%3E10.10.10.10%3C/IPAddress%3E%3CName%3EMACHINE-NAME%3C/Name%3E%3CPAN%3E0%3C/PAN%3E%3C/PreferencesRequest%3E

我知道我们可以对字符串进行编码和解码,但是我认为不需要。

再走一步,我们也尝试过:

$URI="https://uat-somesite.com/folder/broker?ACTION=GETPREFS&REQUEST="
$Body = @"
<?xml%20version='1.0'%20encoding='utf-8'?>
<PreferencesRequest>
<IPAddress>10.10.10.10</IPAddress>
<Name>MACHINE-NAME</Name>
<PAN>0</PAN>
</PreferencesRequest>
"@

iwr $URI –infile $soap

结果是:

iwr : The underlying connection was closed: An unexpected error occurred on a send.
At line:11 char:1
+ iwr $URI –infile $soap
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [In 
   voke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.Invo 
   keWebRequestCommand

谢谢!

0 个答案:

没有答案