【发布时间】:2017-02-23 15:02:11
【问题描述】:
我正在连接到 rest api,它一次只给我 50 个结果的 json 数据,我将结果保存在一个变量中,但我想检索 20000 条记录,我想知道如何构建动态 url获取所有数据并将其保存在变量中。
下面是我当前的代码
$url = "https://org.atlassian.net/rest/api/2/search?jql=project=PS+order+by+key&startAt=0";
$ch = curl_init();
$headers = array('Accept: application/json','Content-Type: application/json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
$json = json_decode($result, true);}
在我的网址中,我有参数来指定我可以从哪个数字返回记录,例如第一个请求将是 startAt=0,第二个将是 startAt=51,thits 将是 startAt=101,或者我可以使用 x = total 这样的公式no of records/50 然后运行 curl x 次并将所有结果保存在变量中或保存所有 json 数组然后合并它。请求你帮助我。
提前致谢
【问题讨论】: