2012-04-16 62 views
1

我现在在soap中使用soap方法创建redbus API。日期时间错误发生在肥皂php

现在我的代码有一些datetime问题。这些是代码

$c = new soapclient('...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); 

它示出了误差作为 致命错误:未捕获的SOAPFault异常:[皂:客户]服务器无法读取请求。 ---> XML文档中存在错误(2,252)。 --->字符串“”是不是一个有效AllXsd值

我这个应该是日期问题

+0

看到这个 - http://stackoverflow.com/questions/6448642/how-to-fix-not-a-valid-allxsd-value-in-objective-c – 2012-04-16 05:41:13

+0

感谢您的意见,但我需要它的代码在php – azarmfa 2012-04-16 08:32:47

回答

1

好吧,如果你需要它在PHP中,这就是:

更换

$sourceid=array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' =>$date); 

$sourceid=array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' =>str_replace($date->format('P'), '', $date->format('c'))); 

希望这有助于。

+0

它不工作,它显示错误为“对象引用未设置为对象的实例”。 – azarmfa 2012-04-16 09:22:54

+0

你能告诉我你的编辑代码吗? – 2012-04-16 09:52:49

+0

<?php $ c = new soapclient('http://www.redbus.in/WS2/BookingService.asmx?wsdl',array('Authentication'=> array('LoginID'=>'x','密码 '=>' X'))); $ timezone = new DateTimeZone('UTC'); $ time ='2012-04-17T16:50:45'; $ date = new DateTime($ time,$ timezone); $ sourceid = array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney'=> str_replace($ date-> format('P'),'',$ date-> format ( 'C' ))); $ stockprice = $ c-> GetAvailableRoutes($ sourceid); print_r($ stockprint); ?> – azarmfa 2012-04-16 10:10:30