【问题标题】:Error when using SoapClient but not when using the web browser使用 SoapClient 时出错,但使用 Web 浏览器时出错
【发布时间】:2016-10-11 13:43:10
【问题描述】:

使用 Chronopost Web 服务。

在网络浏览器中使用这个 post HTTP 请求时(帐号和密码隐藏在那里,所以除非你有 Chronopost ID,否则你无法测试自己):

https://ws.chronopost.fr/shipping-cxf/ShippingServiceWS/shippingWithReservationAndESDWithRefClientPC?subAccount=000&accountNumber=ACCOUNT_NUMBER&password=PASSWORD&shipperCivility=E&shipperName=DELBET&shipperName2=RICHARD&shipperAdress1=1%20rue%20des%20accents&shipperZipCode=28500&shipperCity=Ste%20Gemme%20Moronval&shipperCountry=FR&shipperCountryName=France&shipperContactName=Richard%20Delbet&shipperEmail=richard.delbet@telintrans.fr&shipperPhone=0123456789&shipperMobilePhone=0601020304&recipientCivility=E&recipientName=MALKA&recipientName2=DAVID&recipientAdress1=1%20rue%20des%20essais&recipientZipCode=75001&recipientCity=Paris&recipientCountry=FR&recipientCountryName=France&recipientContactName=David%20Malka&recipientEmail=david.malka@telintrans.fr&recipientPhone=0222426789&recipientMobilePhone=0622220304&shipperRef=CMD1&recipientRef=ART1&productCode=01&shipDate=27/07/2010%2010:00:00&shipHour=10&weight=2&service=0&objectType=MAR&modeRetour=1&mode=PDF

我有一个包含所有正确数据的有效响应。

当使用具有完全相同参数的 SoapClient 时:

$client = new \SoapClient("http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl");
    $data = [
      'subAccount' => '000',
      'accountNumber' => ACCOUNT_NUMBER,
      'password' => PASSWORD,
      'shipperCivility' => 'E',
      'shipperName' => 'DELBET',
      'shipperName2' => 'RICHARD',
      'shipperAdress1' => '1%20rue%20des%20accents',
      'shipperZipCode' => '28500',
      'shipperCity' => 'Ste%20Gemme%20Moronval',
      'shipperCountry' => 'FR',
      'shipperCountryName' => 'France',
      'shipperContactName' => 'Richard%20Delbet',
      'shipperEmail' => 'richard.delbet@telintrans.fr',
      'shipperPhone' => '0123456789',
      'shipperMobilePhone' => '0601020304',
      'recipientCivility' => 'E',
      'recipientName' => 'MALKA',
      'recipientName2' => 'DAVID',
      'recipientAdress1' => '1%20rue%20des%20essais',
      'recipientZipCode' => '75001',
      'recipientCity' => 'Paris',
      'recipientCountry' => 'FR',
      'recipientCountryName' => 'France',
      'recipientContactName' => 'David%20Malka',
      'recipientEmail' => 'david.malka@telintrans.fr',
      'recipientPhone' => '0222426789',
      'recipientMobilePhone' => '0622220304',
      'shipperRef' => 'CMD1',
      'recipientRef' => 'ART1',
      'productCode' => '01',
      'shipDate' => '27/07/2010%2010:00:00',
      'shipHour' => '10',
      'weight' => '2',
      'service' => '0',
      'objectType' => 'MAR',
      'modeRetour' => '1',
      'mode' => 'PDF',
    ];
    $response = $client->__soapCall("shippingWithReservationAndESDWithRefClientPC", array($data));

我返回了一个错误:

object(stdClass)#531 (1) { ["return"]=> object(stdClass)#537 (2) { [“错误代码”]=> 整数(1) [“错误消息”]=> 字符串(3112)“ fr.chronopost.soap.shipping.exception.ValidateException 在 fr.chronopost.soap.shipping.util.PopulateUtils.populateSkybill(PopulateUtils.java:355) 在 fr.chronopost.soap.shipping.cxf.ShippingServiceWS.shippingWithReservationAndESDWithRefClientPC(ShippingServiceWS.java:615) 在 sun.reflect.GeneratedMethodAccessor1258.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:606) 在 org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:136) 在 org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82) 在 org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:54) 在 org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:68) 在 org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56) 在 org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) 在 org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92) 在 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220) 在 org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78) 在 org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92) 在 org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:285) 在 org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:168) 在 org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:175) 在 org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:153) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 在 org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190) 在 org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291) 在 org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776) 在 org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705) 在 org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898) 在 org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690) 在 java.lang.Thread.run(Thread.java:744) " } }

很遗憾,错误代码“1”在文档中被描述为“系统错误”。

可能无法直接帮助我了解 Chronopost Web 服务,但也许我在 PHP SoapClient 对象中遗漏了一些东西。

为什么我在使用 Web 浏览器时会得到正确的响应,而在使用 SoapClient 时会出现某种 ValidateException 错误?

【问题讨论】:

    标签: php web-services soap


    【解决方案1】:

    进行 SOAP 调用时,您不需要包含 URL 编码的数据字符串。 Php soapclient 自动将数据编码为 XML。所以问题很可能是服务对您的数据执行的验证,并且它在 % 字符上阻塞。尝试改变

    'shipDate' => '27/07/2010%2010:00:00'
    

    'shipDate' => '27/07/2010 10:00:00'
    

    【讨论】:

      猜你喜欢
      • 2012-10-06
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多