2

这是我的代码

 $c = new soapclient('http://www.redbus.in/WS2/BookingService.asmx?wsdl',
     array('authentication' => array('LoginID' => 'x','Password'=>'x')));

  $timezone = new DateTimeZone('UTC');
  $time='2012-04-17T16:50:45';
  $date = new DateTime($time,$timezone);
  $sourceid=array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' =>$date);
  $stockprice = $c->GetAvailableRoutes($sourceid);

   print_r($stockprint);

它不适用于日期时间格式数据类型变量

它显示这样的错误

致命错误:未捕获的 SoapFault 异常:[soap:Client] 服务器无法读取请求。---> XML 文档中存在错误 (2, 252)。---> 字符串 '' 不是有效的 AllXsd 值。在 E:\xampplite\htdocs\index1.php:9 堆栈跟踪:#0 [内部函数]:SoapClient->__call('GetAvailableRou...', Array) #1 E:\xampplite\htdocs\index1.php( 9): SoapClient->GetAvailableRoutes(Array) #2 {main} 在第 9 行的 E:\xampplite\htdocs\index1.php 中抛出

4

2 回答 2

11

在使用 PHP 的 SOAP 服务时,我遇到了类似的问题。我使用以下方法修复了它:

$date->format('c');

(ISO 8601 日期,在 PHP 5 中添加,类似于:2004-02-12T15:19:21+00:00)

于 2013-11-18T21:24:57.343 回答
1

您需要对其进行格式化,否则您会将 DateTime 对象扔到您的数组中(PHP 尝试将其转换为字符串,这不起作用)

例如:

$date->format('Y.m.d H:i:s');

用法

$sourceid = array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' => $date->format('Y.m.d H:i:s'));
于 2012-04-16T10:29:59.073 回答