2012-04-16 60 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