Mil*_*ind 2 php jquery restful-url
我是PHP的新手.我想在PHP中调用restful api.我在jQuery中做同样的事情如下
var url;
url = "https://www.example.com/_api/lists/getbytitle('Stations')/items?$select=CityCode,CityNameEN&$filter=Active eq 'Yes'&$orderby=CityNameEN";
$.ajax({
url: url,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
async: false,
success: function (data) {
$.each(data.d.results, function (i, item) {
});
}
});
Run Code Online (Sandbox Code Playgroud)
我怎么能在PHP中做同样的事情.我有两个困难.首先在URL中有$符号,PHP假定为变量,而其他我不知道如何做到这一点
Sah*_*ati 13
使用curl发送HTTP请求.
<?php
$url='https://www.kuwaitairways.com/_api/web/lists/getbytitle(\'Stations\')/items?$select=OfficeId&$filter=CityCode%20eq%20%27KWI%27';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/xml"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)