php - 使用 SoapClient 时出错,但使用 Web 浏览器时不出错

标签 php web-services soap

使用 Chronopost 网络服务。

在网络浏览器中使用此 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) { ["errorCode"]=> int(1) ["errorMessage"]=> string(3112) " fr.chronopost.soap.shipping.exception.ValidateException at fr.chronopost.soap.shipping.util.PopulateUtils.populateSkybill(PopulateUtils.java:355) at fr.chronopost.soap.shipping.cxf.ShippingServiceWS.shippingWithReservationAndESDWithRefClientPC(ShippingServiceWS.java:615) at sun.reflect.GeneratedMethodAccessor1258.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:136) at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82) at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:54) at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:68) at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56) at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78) at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:285) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:168) at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:175) at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:153) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190) at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291) at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776) at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705) at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690) at java.lang.Thread.run(Thread.java:744) " } }

不幸的是,错误代码“1”在文档中被描述为“系统错误”。

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

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

最佳答案

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

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

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

关于php - 使用 SoapClient 时出错,但使用 Web 浏览器时不出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39978701/

相关文章:

php - cURL 请求 Spotify API 意外状态 : 415

PHP 从空查询中获取关联

javascript - JS - 构造数组 - SyntaxError : missing ] after element list

php - 如何识别 PHP 是作为模块安装还是作为 CGI 安装

javascript - 访问 arguments 对象是昂贵的.. 是吗?

java - 以 PDF 作为输入文件的 RESTful Web 服务

c# - 如何在 WCF 服务响应中正确实现自定义 soap 1.2 header 和 WS-Addressing

java - Null ModelAndView 返回到 DispatcherServlet,名称为 'dispatcherServlet' : assuming HandlerAdapter completed request handling

web-services - 列出SharePoint网站中的所有警报,而不使用SharePoint API?

soap - 使用 GSoap 和 SSL 时遇到问题