首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DHL,PHP SOAP速率实现无效

DHL,PHP SOAP速率实现无效
EN

Stack Overflow用户
提问于 2015-12-29 12:09:55
回答 1查看 1.8K关注 0票数 1

你是我最后的希望!我正在尝试实现DHL的评级API到一个网站。他们给我发送了示例代码,我用演示凭证尝试了演示环境,它运行得很好。稍后,他们更改端点url并向我发送永久凭据。从那以后我就没法工作了。我得到了以下错误:

肥皂故障! FaultCode: WSDL FaultString: SOAP-错误:解析WSDL:无法从'https://wsbexpress.dhl.com:443/gbl/expressRateBook‘加载:未能加载外部实体

我的PHP代码如下所示:

代码语言:javascript
复制
    <?php
     // The url of the service 
     $url='https://wsbexpress.dhl.com:443/gbl/expressRateBook';
    // the soap operation which is called
    $action='euExpressRateBook_providerServices_ShipmentHandlingServices_Binder_getRateRequest';

    // the xml input of the service
    $xmlrequest='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rat="http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/RateMsgRequest">

    <soapenv:Header>

     <wsse:Security soapenv:mustunderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:id="UsernameToken-5" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <!-- ####Please use your test user credentials here#### -->
            <wsse:Username>*************</wsse:Username>
            <!-- ####Please use your test user credentials here#### -->
            <wsse:Password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*************</wsse:Password>
            <wsse:Nonce encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">eUYebYfsjztETJ4Urt8AJw==</wsse:Nonce>
            <wsu:Created>2010-02-12T17:40:39.124Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>

   <soapenv:Header/>
   <soapenv:Body>
     <rat:RateRequest>  
    <RequestedShipment>
    <DropOffType>REGULAR_PICKUP</DropOffType>
          <Account>*********</Account>
            <Currency>EUR</Currency>
          <UnitOfMeasurement>SI</UnitOfMeasurement>
         <Ship>
            <Shipper>
                <StreetLines>TEST SHIPPER</StreetLines>
                <City>ALIMOS</City>             
                <PostalCode>174 55</PostalCode>
                <CountryCode>GR</CountryCode>
            </Shipper>
            <Recipient>
                <StreetLines>Main Street</StreetLines>
                <City>GENEVA</City>
                <PostalCode>1201</PostalCode>               
                <CountryCode>CH</CountryCode>
            </Recipient>
        </Ship>
        <Packages>
            <RequestedPackages number="1">
                <Weight>
                    <Value>0.5</Value>
                </Weight>
                <Dimensions>
                    <Length>3</Length>
                    <Width>2</Width>
                    <Height>1</Height>
                </Dimensions>
            </RequestedPackages>
        </Packages>
        <ShipTimestamp>2015-12-28T00:01:00GMT+00:00</ShipTimestamp>
         <Content>NON_DOCUMENTS</Content>
        <PaymentInfo>DAP</PaymentInfo>      
    </RequestedShipment>
     </rat:RateRequest>
   </soapenv:Body>
</soapenv:Envelope>';

    try {

           // the soap client accepts options, we specify the soap version
           // The trace option enables tracing of request so faults can be backtraced.
           // The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault. 

            $options = array(
                'soap_version'=>SOAP_1_1,
                'exceptions'=>true,
                'trace'=>1,
            );

            // create the soapclient and invoke __doRequest method
            $client = new SoapClient($url, $options);
            $output= $client->__doRequest($xmlrequest, $url, $action, 1);       
        }
        catch (SoapFault $fault) {
            echo "<h2>SOAP Fault!</h2><p>";
            echo "FaultCode: {$fault->faultcode} <br/>";
            echo "FaultString: {$fault->faultstring} <br/>";
            echo("</p/>");
       }

    echo ("<h2>WSDL URL: </h2><p>");    
    echo ($url);
    echo("</p/>");

    echo ("<h2>Action: </h2><p>");        
    echo ($action);
    echo("</p/>");

    echo("<h2>XMLRequest: </h2><p>");
    echo ($xmlrequest);
    echo("</p/>");

    if (!isset($output)) {
      echo "<h2>SOAP Fault!</h2><p>";
      echo "FaultCode: {$output->faultcode} <br/>";
      echo "FaultString: {$output->faultstring} <br/>";
   }else{
      echo("<h2>Output: </h2><p>");
      echo $output;
      echo("</p/>");
}
?>

其中*我的实际全权证书。如果我给出端点url

https://wsbexpress.dhl.com/gbl/expressRateBook?wsdl

我得到的响应是SOAP模式。你能帮我找出哪里出了问题吗?我没有得到正确的回应?

EN

回答 1

Stack Overflow用户

发布于 2018-07-03 12:34:03

试着尝试这样的选项:

代码语言:javascript
复制
$opts = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

$options = array (
    'encoding' => 'UTF-8',
    'verifypeer' => false,
    'verifyhost' => false,
    'soap_version' => SOAP_1_2,
    'trace' => 1,
    'exceptions' => 1,
    'connection_timeout' => 180,
    'stream_context' => stream_context_create($opts),
    'cache_wsdl' => WSDL_CACHE_NONE,
    //'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 1
);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34510778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档