Note that there are some explanatory texts on larger screens.

plurals
  1. POSend XML with php via post
    primarykey
    data
    text
    <p>I know there are any number of similar questions to this on SO, but I've tried messing around with all the solutions and haven't seemed to be able to make it work. I am trying to post xml directly to a web service and get a response back. Technically I am trying to connect to freightquote.com, the documentation for which you can find in the upper right hand corner of <a href="https://b2b.freightquote.com/faqs.aspx" rel="nofollow">this</a> page under documentation. I only mention that because I see the term SOAP a lot in their xml and it might make a difference. Anyway what I want is the ability to send xml to some url and get a response back. </p> <p>So if I had the following </p> <pre><code>$xml = "&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt; &lt;soap:Body&gt; &lt;GetRatingEngineQuote xmlns='http://tempuri.org/'&gt; &lt;request&gt; &lt;CustomerId&gt;0&lt;/CustomerId&gt; &lt;!-- Identifier for customer provided by Freightquote --&gt; &lt;QuoteType&gt;B2B&lt;/QuoteType&gt; &lt;!-- B2B / eBay /Freightview --&gt; &lt;ServiceType&gt;LTL&lt;/ServiceType&gt; &lt;!-- LTL / Truckload / Groupage / Haulage / Al --&gt; &lt;QuoteShipment&gt; &lt;IsBlind&gt;false&lt;/IsBlind&gt; &lt;PickupDate&gt;2010-09-13T00:00:00&lt;/PickupDate&gt; &lt;SortAndSegregate&gt;false&lt;/SortAndSegregate&gt; &lt;ShipmentLocations&gt; &lt;Location&gt; &lt;LocationType&gt;Origin&lt;/LocationType&gt; &lt;RequiresArrivalNotification&gt;false&lt;/RequiresArrivalNotification&gt; &lt;HasDeliveryAppointment&gt;false&lt;/HasDeliveryAppointment&gt; &lt;IsLimitedAccess&gt;false&lt;/IsLimitedAccess&gt; &lt;HasLoadingDock&gt;false&lt;/HasLoadingDock&gt; &lt;IsConstructionSite&gt;false&lt;/IsConstructionSite&gt; &lt;RequiresInsideDelivery&gt;false&lt;/RequiresInsideDelivery&gt; &lt;IsTradeShow&gt;false&lt;/IsTradeShow&gt; &lt;IsResidential&gt;false&lt;/IsResidential&gt; &lt;RequiresLiftgate&gt;false&lt;/RequiresLiftgate&gt; &lt;LocationAddress&gt; &lt;PostalCode&gt;30303&lt;/PostalCode&gt; &lt;CountryCode&gt;US&lt;/CountryCode&gt; &lt;/LocationAddress&gt; &lt;AdditionalServices /&gt; &lt;/Location&gt; &lt;Location&gt; &lt;LocationType&gt;Destination&lt;/LocationType&gt; &lt;RequiresArrivalNotification&gt;false&lt;/RequiresArrivalNotification&gt; &lt;HasDeliveryAppointment&gt;false&lt;/HasDeliveryAppointment&gt; &lt;IsLimitedAccess&gt;false&lt;/IsLimitedAccess&gt; &lt;HasLoadingDock&gt;false&lt;/HasLoadingDock&gt; &lt;IsConstructionSite&gt;false&lt;/IsConstructionSite&gt; &lt;RequiresInsideDelivery&gt;false&lt;/RequiresInsideDelivery&gt; &lt;IsTradeShow&gt;false&lt;/IsTradeShow&gt; &lt;IsResidential&gt;false&lt;/IsResidential&gt; &lt;RequiresLiftgate&gt;false&lt;/RequiresLiftgate&gt; &lt;LocationAddress&gt; &lt;PostalCode&gt;60606&lt;/PostalCode&gt; &lt;CountryCode&gt;US&lt;/CountryCode&gt; &lt;/LocationAddress&gt; &lt;AdditionalServices /&gt; &lt;/Location&gt; &lt;/ShipmentLocations&gt; &lt;ShipmentProducts&gt; &lt;Product&gt; &lt;Class&gt;55&lt;/Class&gt; &lt;Weight&gt;1200&lt;/Weight&gt; &lt;Length&gt;0&lt;/Length&gt; &lt;Width&gt;0&lt;/Width&gt; &lt;Height&gt;0&lt;/Height&gt; &lt;ProductDescription&gt;Books&lt;/ProductDescription&gt; &lt;PackageType&gt;Pallets_48x48&lt;/PackageType&gt; &lt;IsStackable&gt;false&lt;/IsStackable&gt; &lt;DeclaredValue&gt;0&lt;/DeclaredValue&gt; &lt;CommodityType&gt;GeneralMerchandise&lt;/CommodityType&gt; &lt;ContentType&gt;NewCommercialGoods&lt;/ContentType&gt; &lt;IsHazardousMaterial&gt;false&lt;/IsHazardousMaterial&gt; &lt;PieceCount&gt;5&lt;/PieceCount&gt; &lt;ItemNumber&gt;0&lt;/ItemNumber&gt; &lt;/Product&gt; &lt;/ShipmentProducts&gt; &lt;ShipmentContacts /&gt; &lt;/QuoteShipment&gt; &lt;/request&gt; &lt;user&gt; &lt;Name&gt;someone@something.com&lt;/Name&gt; &lt;Password&gt;password&lt;/Password&gt; &lt;/user&gt; &lt;/GetRatingEngineQuote&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt;"; </code></pre> <p>(I edited this to contain my actual xml since it may lend some perspective</p> <p>I'd want to send it to <a href="http://www.someexample.com" rel="nofollow">http://www.someexample.com</a> and get a response. Also, do I need to encode it? I've done a lot of sending xml back and forth with android, and never had to but that might be part of my problem.</p> <p>My attempt to send the information currently looks like this </p> <pre><code>$xml_post_string = 'XML='.urlencode($xml-&gt;asXML()); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://b2b.Freightquote.com/WebService/QuoteService.asmx'); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); </code></pre>
    singulars
    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.
 

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