简体   繁体   中英

how to make SoapUi request in powershell which requires header cookie?

I have some web-service calls in soapui. I want to put them in a script so I can make them as monitor calls. Not sure what would be the best option to proceed. Thinking to write ps script to make those calls and use script to urn as a monitor. Please advice if you have a better suggestion. Appreciate your help! - Sam

Well, you can send a SOAP request like this:

$soap = @"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <Geocode xmlns="http://dev.virtualearth.net/webservices/v1/geocode/contracts">
         <request xmlns:a="http://dev.virtualearth.net/webservices/v1/geocode" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <Credentials xmlns="http://dev.virtualearth.net/webservices/v1/common">
               <ApplicationId>ThisIsMySecret</ApplicationId>
               <Token i:nil="true" />
            </Credentials>
            <Culture xmlns="http://dev.virtualearth.net/webservices/v1/common" i:nil="true" />
            <ExecutionOptions xmlns="http://dev.virtualearth.net/webservices/v1/common" i:nil="true" />
            <UserProfile xmlns="http://dev.virtualearth.net/webservices/v1/common" i:nil="true" />
            <a:Address xmlns:b="http://dev.virtualearth.net/webservices/v1/common">
               <b:AddressLine>1747 Reynolds St NW</b:AddressLine>
               <b:AdminDistrict>TN</b:AdminDistrict>
               <b:CountryRegion i:nil="true" />
               <b:District i:nil="true" />
               <b:FormattedAddress i:nil="true" />
               <b:Locality>Knoxville</b:Locality>
               <b:PostalCode>37921</b:PostalCode>
               <b:PostalTown i:nil="true" />
            </a:Address>
            <a:Options i:nil="true" />
            <a:Query i:nil="true" />
         </request>
      </Geocode>
   </s:Body>
</s:Envelope>
"@

$headers = @{ 
    'Content-Type' = 'text/xml; charset=utf-8'; 
    'SOAPAction' = 'http://dev.virtualearth.net/webservices/v1/geocode/contracts/IGeocodeService/Geocode' 
}

Invoke-WebRequest `
    -Uri http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc `
    -Body $soap `
    -Method Post `
    -Headers $headers

If you need to add a cookie you can just add the string to $headers :

$headers = @{ 
    'Content-Type' = 'text/xml; charset=utf-8'; 
    'SOAPAction' = 'http://dev.virtualearth.net/webservices/v1/geocode/contracts/IGeocodeService/Geocode';
    'Cookie' = 'YouCookieGoesHere'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM