2017-09-21 100 views
0

預先感謝您 我試着用捲曲使用獲得的OData服務的URL下面的代碼OData服務不能完全返回JSON在PHP捲曲

<?php 
$url = "serviceurl/odata.srv/Users?$format=json&$expand=EmployeeDetails/ClientDetails/ClientConfigurationDetails,EmployeeDetails/ClientDetails/LogoDetails,SalutationTexts,UserConfigurationDetails"; 



$ch = curl_init($url); // such as http://example.com/example.xml 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, "username:password"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json', 
'Accept: application/json')); 
curl_setopt($ch, CURLOPT_POST, 0); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

$data = curl_exec($ch); 
curl_close($ch); 

echo $data; 

僅造成用戶詳細介紹了擴大細節並不存在,但在郵遞員並直接在瀏覽器中調用它的做工精細獲得所有細節

回答

1

把它的URL在單引號像下面

$url = 'serviceurl/odata.srv/Users?$format=json&$expand=EmployeeDetails/ClientDetails/ClientConfigurationDetails,EmployeeDetails/ClientDetails/LogoDetails,SalutationTexts,UserConfigurationDetails'; 

WHI le使用雙引號php將嘗試替換$ format和$ expand變量,這些變量實際上是odata參數而不是php變量。

希望這會有所幫助。

+0

這是我的錯誤,我忘了在URL中的特殊字符 –