Note that there are some explanatory texts on larger screens.

plurals
  1. POSOAP Parsing from cURL request to Web Services
    primarykey
    data
    text
    <p>I currently have a script parsing data from a Web Service, all examples I've found so far tell me the result is just to be parsed as XML, but without the result actually being valid XML this is a bit difficulty.</p> <hr> <p>My XML Request sent to the Web Service:</p> <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.bring.no/logistics/shippingguide/1.0"&gt; &lt;soapenv:Header/&gt; &lt;soapenv:Body&gt; &lt;ns:ShippingGuideRequest&gt; &lt;ns:UserInformation&gt; &lt;ns:Usercode&gt;ae34ab27-2023-41f5-b800-013f0d0a6015&lt;/ns:Usercode&gt; &lt;/ns:UserInformation&gt; &lt;ns:ProductIds&gt; &lt;ns:ProductId&gt;SERVICEPAKKE&lt;/ns:ProductId&gt; &lt;/ns:ProductIds&gt; &lt;ns:Packages&gt; &lt;ns:Package packageId="7,"&gt; &lt;ns:GrossWeight unitCode="GRM"&gt;500&lt;/ns:GrossWeight&gt; &lt;ns:FromPostalCode&gt;4045&lt;/ns:FromPostalCode&gt; &lt;ns:ToPostalCode&gt;4045&lt;/ns:ToPostalCode&gt; &lt;/ns:Package&gt; &lt;/ns:Packages&gt; &lt;/ns:ShippingGuideRequest&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt; </code></pre> <p>I am NOT able to use the built in SoapClient that comes with PHP5 and above, as I do not approve of forcing my users to have this configured as I've experienced many of my test cases to not have. I have tried doing the request using plain sockets as well as cURL, but this did not yield any different results.</p> <hr> <p>The result I get from the call is as follows;</p> <pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;SOAP-ENV:Header/&gt;&lt;SOAP-ENV:Body&gt;&lt;ns:ShippingGuideResponse xmlns:ns="http://www.bring.no/logistics/shippingguide/1.0"&gt;&lt;ns:Packages&gt;&lt;ns:Package packageId="7,"&gt;&lt;ns:Product&gt;&lt;ns:ProductId&gt;SERVICEPAKKE&lt;/ns:ProductId&gt;&lt;ns:GuiInformation&gt;&lt;ns:SortOrder&gt;11&lt;/ns:SortOrder&gt;&lt;ns:MainDisplayCategory&gt;Hent sendingen selv&lt;/ns:MainDisplayCategory&gt;&lt;ns:SubDisplayCategory/&gt;&lt;ns:DisplayName&gt;På postkontor eller post i butikk&lt;/ns:DisplayName&gt;&lt;ns:ProductName&gt;Klimanøytral Servicepakke&lt;/ns:ProductName&gt;&lt;ns:DescriptionText&gt;Madla. Åpningstider Man - Fre: 1000-1800, Lør: 1000-1500&lt;/ns:DescriptionText&gt;&lt;ns:HelpText&gt;Sendingen er en Klimanøytral Servicepakke som blir levert til mottakers postkontor/ post i butikk. Mottaker kan velge å hente sendingen på et annet postkontor/post i butikk enn sitt lokale. Mottaker varsles om at sendingen er ankommet via SMS, e-post eller hentemelding i postkassen. Transporttid er normalt 1-3 virkedager, avhengig av strekning. Sendingen kan spores ved hjelp av sporingsnummeret.&lt;/ns:HelpText&gt;&lt;ns:Tip/&gt;&lt;/ns:GuiInformation&gt;&lt;ns:Price currencyIdentificationCode="NOK"&gt;&lt;ns:PackagePriceWithoutAdditionalServices&gt;&lt;ns:AmountWithoutVAT&gt;66.00&lt;/ns:AmountWithoutVAT&gt;&lt;ns:VAT&gt;16.50&lt;/ns:VAT&gt;&lt;ns:AmountWithVAT&gt;82.50&lt;/ns:AmountWithVAT&gt;&lt;/ns:PackagePriceWithoutAdditionalServices&gt;&lt;/ns:Price&gt;&lt;ns:ExpectedDelivery&gt;&lt;ns:WorkingDays&gt;1&lt;/ns:WorkingDays&gt;&lt;ns:UserMessage/&gt;&lt;ns:AlternativeDeliveryDates/&gt;&lt;/ns:ExpectedDelivery&gt;&lt;/ns:Product&gt;&lt;/ns:Package&gt;&lt;/ns:Packages&gt;&lt;ns:TraceMessages&gt;&lt;ns:Message&gt;You are using an outdated schema version (1). Most recent schema version is 4.&lt;/ns:Message&gt;&lt;/ns:TraceMessages&gt;&lt;/ns:ShippingGuideResponse&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt; </code></pre> <hr> <p>As you can see the XML request is lacking the XML start tags, and as such SimpleXMLElement and similar in PHP is unable to interpret it.</p> <p>Finally, the code I use to send my request, hopefully it's something trivial like a header I'm missing or similar.</p> <blockquote> <p>$ch = curl_init("http://fraktguide.bring.no/fraktguide/ws/1.0/");</p> <p>curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: ' . strlen($xml) ));</p> <p>curl_setopt($ch, CURLOPT_POST, 1);</p> <p>curl_setopt($ch, CURLOPT_TIMEOUT, 30);</p> <p>curl_setopt($ch, CURLOPT_PORT, 80);</p> <p>curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);</p> <p>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);</p> <p>curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);</p> <p>curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);</p> <p>curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);</p> <p>$result = curl_exec($ch);</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload