我需要从Powershell发出Soap Request,我在Powershell 2.0上,我可以找到很多示例,但是我还需要包括用户名和密码才能通过api。
我得到了一个回应 带有“ 0”参数的调用“ GetResponse”的异常:“底层连接 n已关闭:发送时发生意外错误。”
我的Powershell代码(我编辑了一些敏感的东西)是
int
我可以通过SOAPUI获得调用,原始XML是
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","`"`"")
$soapWebRequest.ContentType = "text/xml;charset=`"utf-8`""
$soapWebRequest.Accept = "text/xml"
$soapWebRequest.Method = "POST"
$username = "USERNAME"
$password = "Password" | ConvertTo-SecureString -asPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($username,$password)
$soapWebRequest.Credentials = $cred
#$soapWebRequest.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
#$soapWebRequest.UseDefaultCredentials = $true
write-host $soapWebRequest
write-host "Initiating Send."
$requestStream = $soapWebRequest.GetRequestStream()
write-host $requestStream
$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 = 'https://zkncsavia049.via.novonet:7180/ws/activeservices/pmspapi_nomination'
$soap = [xml]@'
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:pms="http://www.mydomain.co.uk/pmsapi_nomination" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wssu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soapenv:Header><wsse:Security><wsse:UsernameToken wssu:Id="UsernameToken-4B81F4838BB6D8A60715299310629901"><wsse:Username>igyadmin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">V3rm0nt</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">x9DSipKzGHLbvyCOXKIY6A==</wsse:Nonce>
<wssu:Created>2018-06-25T12:51:02.986Z</wssu:Created></wsse:UsernameToken></wsse:Security>
</soapenv:Header>
<soapenv:Body>
<pms:pmsapi_nomination.getlist.ApiRequest xmlns:ns2="http://www.mydomain.co.uk/pmsapi_nomination">
<ApiRequest>
<LogonInfo>
<BusinessGroup>GMP</BusinessGroup>
<AdminGroup>ADMN</AdminGroup>
</LogonInfo>
<BUSINESS_GROUP>
<value>GMP</value>
</BUSINESS_GROUP>
<CONTEXT>
<value>F</value>
</CONTEXT>
<REFNO>
<value>0039760</value>
</REFNO>
</ApiRequest>
</pms:pmsapi_nomination.getlist.ApiRequest>
</soapenv:Body>
</soapenv:Envelope>
'@
$ret = Execute-SOAPRequest $soap $url
系统上有SSL证书,但端口7180没有。
我也是超级新手,我一年只写几次。
所以失败还在继续
POST http://zkncsavia049.via.novonet:7180/ws/activeservices/pmsapi_nomination/HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 1541
Host: zkncsavia049.via.novonet:7180
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:pms="http://www.mydomain.co.uk/pmsapi_nomination" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wssu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soapenv:Header><wsse:Security><wsse:UsernameToken wssu:Id="UsernameToken-78C15367B2B1287BB3153000735070610"><wsse:Username>USERNAME</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">q5B6XRmHsecmHouCqH03qA==</wsse:Nonce><wssu:Created>2018-06-26T10:02:30.696Z</wssu:Created></wsse:UsernameToken></wsse:Security>
</soapenv:Header>
<soapenv:Body>
<pms:pmsapi_nomination.getlist.ApiRequest xmlns:ns2="http://www.aquilauk.co.uk/pmsapi_nomination">
<ApiRequest>
<LogonInfo>
<BusinessGroup>GMP</BusinessGroup>
<AdminGroup>ADMN</AdminGroup>
</LogonInfo>
<BUSINESS_GROUP>
<value>GMP</value>
</BUSINESS_GROUP>
<CONTEXT>
<value>F</value>
</CONTEXT>
<REFNO>
<value>0039761</value>
</REFNO>
</ApiRequest>
</pms:pmsapi_nomination.getlist.ApiRequest>
</soapenv:Body>
</soapenv:Envelope>
但是我想可能是$ soapWebRequest的设置