我知道在 SO 上有很多类似的问题,但我已经尝试过所有的解决方案,但似乎无法让它发挥作用。我正在尝试将 xml 直接发布到 Web 服务并得到响应。从技术上讲,我正在尝试连接到freightquote.com,您可以在本页右上角的 文档下找到该文档。我只提到这一点是因为我在他们的 xml 中经常看到术语 SOAP,它可能会有所作为。无论如何,我想要的是能够将 xml 发送到某个 url 并得到回复。
所以如果我有以下
$xml = "<?xml version='1.0' encoding='utf-8'?>
<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'>
<soap:Body>
<GetRatingEngineQuote xmlns='http://tempuri.org/'>
<request>
<CustomerId>0</CustomerId> <!-- Identifier for customer provided by Freightquote -->
<QuoteType>B2B</QuoteType> <!-- B2B / eBay /Freightview -->
<ServiceType>LTL</ServiceType> <!-- LTL / Truckload / Groupage / Haulage / Al -->
<QuoteShipment>
<IsBlind>false</IsBlind>
<PickupDate>2010-09-13T00:00:00</PickupDate>
<SortAndSegregate>false</SortAndSegregate>
<ShipmentLocations>
<Location>
<LocationType>Origin</LocationType>
<RequiresArrivalNotification>false</RequiresArrivalNotification>
<HasDeliveryAppointment>false</HasDeliveryAppointment>
<IsLimitedAccess>false</IsLimitedAccess>
<HasLoadingDock>false</HasLoadingDock>
<IsConstructionSite>false</IsConstructionSite>
<RequiresInsideDelivery>false</RequiresInsideDelivery>
<IsTradeShow>false</IsTradeShow>
<IsResidential>false</IsResidential>
<RequiresLiftgate>false</RequiresLiftgate>
<LocationAddress>
<PostalCode>30303</PostalCode>
<CountryCode>US</CountryCode>
</LocationAddress>
<AdditionalServices />
</Location>
<Location>
<LocationType>Destination</LocationType>
<RequiresArrivalNotification>false</RequiresArrivalNotification>
<HasDeliveryAppointment>false</HasDeliveryAppointment>
<IsLimitedAccess>false</IsLimitedAccess>
<HasLoadingDock>false</HasLoadingDock>
<IsConstructionSite>false</IsConstructionSite>
<RequiresInsideDelivery>false</RequiresInsideDelivery>
<IsTradeShow>false</IsTradeShow>
<IsResidential>false</IsResidential>
<RequiresLiftgate>false</RequiresLiftgate>
<LocationAddress>
<PostalCode>60606</PostalCode>
<CountryCode>US</CountryCode>
</LocationAddress>
<AdditionalServices />
</Location>
</ShipmentLocations>
<ShipmentProducts>
<Product>
<Class>55</Class>
<Weight>1200</Weight>
<Length>0</Length>
<Width>0</Width>
<Height>0</Height>
<ProductDescription>Books</ProductDescription>
<PackageType>Pallets_48x48</PackageType>
<IsStackable>false</IsStackable>
<DeclaredValue>0</DeclaredValue>
<CommodityType>GeneralMerchandise</CommodityType>
<ContentType>NewCommercialGoods</ContentType>
<IsHazardousMaterial>false</IsHazardousMaterial>
<PieceCount>5</PieceCount>
<ItemNumber>0</ItemNumber>
</Product>
</ShipmentProducts>
<ShipmentContacts />
</QuoteShipment>
</request>
<user>
<Name>someone@something.com</Name>
<Password>password</Password>
</user>
</GetRatingEngineQuote>
</soap:Body>
</soap:Envelope>";
(我编辑了这个以包含我的实际 xml,因为它可能会提供一些视角
我想将它发送到http://www.someexample.com并得到回复。另外,我需要对其进行编码吗?我已经用 android 来回发送了很多 xml,但从来没有这样做过,但这可能是我的问题的一部分。
我目前发送信息的尝试看起来像这样
$xml_post_string = 'XML='.urlencode($xml->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);