您现在的位置是:网站首页> 编程资料编程资料
PowerShell小技巧之执行SOAP请求_PowerShell_
2023-05-26
449人已围观
简介 PowerShell小技巧之执行SOAP请求_PowerShell_
SOAP的请求在Web Service是无处不在的,像WCF服务和传统ASMX asp.net的web Service。如果要测试SOAP服务是否好用通过web编程来实现就显得太过于复杂了,下面的脚本片段(snippet)将会轻而易举的完成通过powershell测试和调用SOAP服务:
这是一段程序代码。
复制代码 代码如下:
function Execute-SOAPRequest
(
[Xml] $SOAPRequest,
[String] $URL
)
{
write-host "Sending SOAP Request To Server: $URL"
$soapWebRequest = [System.Net.WebRequest]::Create($URL)
$soapWebRequest.Headers.Add("SOAPAction","`"http://www.facilities.co.za/valid8service/valid8service/Valid8Address`"")
$soapWebRequest.ContentType = "text/xml;charset=`"utf-8`""
$soapWebRequest.Accept = "text/xml"
$soapWebRequest.Method = "POST"
write-host "Initiating Send."
$requestStream = $soapWebRequest.GetRequestStream()
$SOAPRequest.Save($requestStream)
$requestStream.Close()
write-host "Send Complete, Waiting For Response."
$resp = $soapWebRequest.GetResponse()
$responseStream = $resp.GetResponseStream()
$soapReader = [System.IO.StreamReader]($responseStream)
$ReturnXml = [Xml] $soapReader.ReadToEnd()
$responseStream.Close()
write-host "Response Received."
return $ReturnXml
}
$url = 'http://www.facilities.co.za/valid8service/valid8service.asmx'
$soap = [xml]@'
'@
$ret = Execute-SOAPRequest $soap $url
在这里得到的$ret变量中存储的是System.Xml.XmlDocument对象,如果需要查看其中的具体内容可以通过Export-Clixml这个cmdlet将其输出到本地文件中查看。
这是一段程序代码。
复制代码 代码如下:
$ret | Export-Clixml c:\1.xml;Get-Content c:\1.xml
您可能感兴趣的文章:
相关内容
- PowerShell小技巧之尝试ssh登录_PowerShell_
- PowerShell小技巧之发送TCP请求_PowerShell_
- PowerShell小技巧之读取Windows产品密钥_PowerShell_
- PowerShell小技巧之定时记录操作系统行为_PowerShell_
- PowerShell小技巧之定时抓取屏幕图像_PowerShell_
- PowerShell小技巧之实现文件下载(类wget)_PowerShell_
- PowerShell小技巧之获取域名whois信息_PowerShell_
- PowerShell小技巧之获取Windows系统密码Hash_PowerShell_
- PowerShell小技巧之获取TCP响应(类Telnet)_PowerShell_
- Powershell小技巧之捕获脚本内部的异常_PowerShell_
