代码之家  ›  专栏  ›  技术社区  ›  Tijo John

Odata服务在php Curl中未完全返回json

  •  0
  • Tijo John  · 技术社区  · 7 年前

    提前谢谢你 我尝试使用以下代码使用curl获取odata服务url

    <?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 回复  |  直到 7 年前
        1
  •  1
  •   Jyothish V    7 年前

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

    在使用双引号时,php将尝试替换$format和$expand变量,它们实际上是odata参数,而不是php变量。