2016-12-16 16 views
2

私はSoap Apiには新しく、SOAPリクエストについてはわかりません。私はPHPを使用してAPIを呼び出す方法については、理想を持っていない。以下はapi xlmのパラメータです。soap apiを呼び出す

<xsd:user_id>[email protected]</xsd:user_id> 
<xsd:password>uss</xsd:password> 
<xsd:shipment> 
    <xsd1:courier>L</xsd1:courier> 
    <xsd1:delivery_address_line_1>123 MAIN ST</xsd1:delivery_address_line_1> 
</xsd:shipment> 

私はカールとSOAPサーバーを呼び出すコード

 $xml_post_string = ''; 
     $soapUrl = 'https://sandbox.loomis-express.com/axis2/services/USSBusinessService?wsdl'; 
     $headers = array(
        "Content-type: text/xml;charset=\"utf-8\"", 
        "Accept: text/xml", 
        "Cache-Control: no-cache", 
        "Pragma: no-cache", 
        "SOAPAction: $soapUrl", 
        "Content-length: ".strlen($xml_post_string), 
       ); //SOAPAction: your op URL 




     $url = $soapUrl; 

     // PHP cURL for https connection with auth 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc 
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request 
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

     // converting 
     $response = curl_exec($ch); 
     curl_close($ch); 

の下に事前

答えて

0

に感謝を使用して、このAPIを呼び出すしよう本当にこれを行うには難しい方法であり、いくつかの経験が必要です。 まずは、 空の変数を指定されたサーバーにポストしています。

$xml_post_string = ''; 

期待されるxmlをこの変数に入れる必要があります。あなたのコードでWsdlサービスをチェックしました。 SoapUIを使ってSoap Serverが期待するXMLとヘッダパラメータの種類を確認することをお勧めします。

たとえば、この石鹸サーバーにはgetVersionメソッドがあります。 SoapUIでこのメソッドを呼び出すと、Request XMLとRaw Responseの例が得られます。

要求XML(あなたのカールのリクエストでこれを掲示しなければならない):この要求の

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://ws.business.uss.transforce.ca"> 
    <soap:Header/> 
    <soap:Body> 
     <ws:getVersion/> 
    </soap:Body> 
</soap:Envelope> 

期待ヘッダ(そして、あなたがあなたのカールリクエストにこのヘッダを追加する必要があります):

Content-Type: application/soap+xml;charset=UTF-8;action="urn:getVersion" 
Host: sandbox.loomis-express.com 

そして、応答:

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns:getVersionResponse xmlns:ns="http://ws.business.uss.transforce.ca"><ns:return xmlns:ax27="http://dto.uss.transforce.ca/xsd" xmlns:ax25="http://ws.business.uss.transforce.ca/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax25:GetVersionRs"><ax25:error xsi:nil="true" /><ax25:version>3.1.8</ax25:version></ns:return></ns:getVersionResponse></soapenv:Body></soapenv:Envelope> 

PHPの石鹸クライアントを使用することをお勧めします。ここには良いスレッドがあります:How to make a PHP SOAP call using the SoapClient class

関連する問題