SOAP WSDL 请求 - 方法返回错误请求错误

我正在尝试打一个肥皂电话,它返回一个“错误请求”错误。


示例调用是:


    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://centric.eu/services/CS/Trade/Standard/WS/" xmlns:cen="http://schemas.datacontract.org/2004/07/Centric.CS.Trade.Standard.WS.StockService.Contract.Request">

<soapenv:Header>

    <ws:Security soapenv:mustUnderstand="1" xmlns:ws="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

        <ws:UsernameToken>

            <ws:Username>username</ws:Username>

            <ws:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</ws:Password>

         </ws:UsernameToken>

    </ws:Security>

</soapenv:Header>

   <soapenv:Body>

      <ws:GetStock>

         <ws:request>

            <cen:StockRequests>

               <!--Zero or more repetitions:-->

               <cen:StockRequest>

                  <cen:CustomerNo>123</cen:CustomerNo>

                  <cen:Division>AGU_NL</cen:Division>

                  <cen:Item>113504</cen:Item>

                  <cen:Language>NL</cen:Language>

                  <cen:Login>123</cen:Login>

               </cen:StockRequest>

            </cen:StockRequests>

         </ws:request>

      </ws:GetStock>

   </soapenv:Body>

</soapenv:Envelope>

我使用以下代码:


$soapclient = new \SoapClient($url, array(

            'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 9,

            'trace' => true,

            'exceptions' => 1,

            'cache_wsdl' => 1,

        ));


我得到的响应是:错误代码:HTTP,错误字符串:错误请求 我不完全确定我是否创建了请求并正确调用了该方法。


任何帮助将不胜感激


慕慕森
浏览 289回答 2
2回答

牛魔王的故事

您最好不要尝试手动构建 xml。请尝试以下方法:$url = 'https://webservices.abcb2b.eu/Centric/CS/Trade/csprod/StockService.svc?wsdl';$username = 'username';$password = 'pass';$client = new SoapClient($url, array('trace' => 1, "exception" => 0));$wssNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";$usernameToken = new SoapVar(array(&nbsp; &nbsp; new SoapVar(array(&nbsp; &nbsp; &nbsp; &nbsp; new SoapVar($username, XSD_STRING, null, null, 'Username', $wssNamespace),&nbsp; &nbsp; &nbsp; &nbsp; new SoapVar($password, XSD_STRING, null, null, 'Password', $wssNamespace)&nbsp; &nbsp; ), SOAP_ENC_OBJECT, null, null, 'UsernameToken', $wssNamespace)), SOAP_ENC_OBJECT, null, null, null, $wssNamespace);$client->__setSoapHeaders(new SoapHeader($wssNamespace, 'Security', $usernameToken));try {&nbsp; &nbsp; $client->GetStock(array(&nbsp; &nbsp; &nbsp; &nbsp; 'request' => array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'StockRequests' => array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'StockRequest' => array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'CustomerNo' => 123,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Division' => 'AGU_NL',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Item' => '113504',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Language' => 'NL',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Login' => '123',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; ));} catch(\SoapFault $e) {&nbsp; &nbsp; echo '<pre>';&nbsp; &nbsp; print_r($e->getMessage());&nbsp; &nbsp; echo '</pre>';}

UYOU

您收到错误请求的原因是因为您没有很好地格式化您的请求,如果您的请求之间没有空格,请尝试制作
打开App,查看更多内容
随时随地看视频慕课网APP