此REST API的正确数据格式是什么



我有一个API url,看起来像这样:

"https://cloud.XXXXXXXXX.com/api/data/XXXXXXX2017112020-804?from=2021-1-1T00:00:00&to=2021-2-26T00:00:00&平均周期=60&includejournal=false";

Api使用此格式解码URL并从Endpoint获取我需要的数据:我使用的方法是"GET",URL如下所示:'api/数据/串行?from=开始时间&to=结束时间&averagingperiod=平均周期&includejournal=包括日记账'

api/数据在哪里是标准的和/串行的?是端点的序列号。(?from=(和(&to=(是我使用ISO8601规则设置的参数。但我需要将24小时前的时间(from=(设置为当前时间,例如:(?from=".date('Y-m-d',$yesterday("T"00:00:00"amp;to="。日期("Y-m-d"("T"00:00:00"。(

日期和时间格式如下:(yyyy-mm-ddTT00:00:00(

我的代码如下:

<?php
// get the timestamp of yesterday
$yesterday = strtotime('-24 Hours');
// get the timestamp of today
$today = date();
// the format we build the date in
$format = 'Y-m-d';
// get the yesterday in the specified format
$from = date($format, $yesterday);
// get today in the specified format
$to = date($format, $today);
// build the URL
$url = 'https://cloud.aeroqual.com/api/data/AQM65%2017112020-804'.'?from='.$from.'T00:00:00'.'&to='.$to.'T00:00:00'.'&averagingperiod=60&includejournal=false'.;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Cookie: .MONOAUTH=C5PBclbeW29kqexXRGTlXaHImDoLhxR/YzALxc44/SZ+KQV2XuMsZps6OJnXMSi56gjRsQ6ED6GIcH7Fk8XCoJ80IrpsTUDPO+Bmf0tVKaPZtIzpwe7ff3QqBKZLFGZK; ASP.NET_SessionId=9F89912F7F571A228B63ACEC; AWSELB=95CB9B4302EC8CCB93BD1C1D5C4630880B3D9B3CCF5F0CE3F60EF45F0604C252A119CAE7D802D28AE24434CB392308307A6E5617B4045026B161BDB6886AF9E5C0388BFFED; AWSELBCORS=95CB9B4302EC8CCB93BD1C1D5C4630880B3D9B3CCF5F0CE3F60EF45F0604C252A119CAE7D802D28AE24434CB392308307A6E5617B4045026B161BDB6886AF9E5C0388BFFED'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

问题:如何格式化我的URL,以便接收24小时前到现在(当前时间(的数据。或者,如果有人知道,是否可以在cURL的URL中实现变量。

错误:在服务器上运行php代码时,我会收到以下错误:

1:加载资源失败:服务器响应,状态为500((2:VM265:7146 crbug/1173575,不赞成使用非JS模块文件。(匿名(@VM265:7146

这段代码运行得很好,但我想获得从24小时前到当前时间的日期和时间值。:

<?php
$ch = curl_init();
// Configure curl as needed, depending on your application
curl_setopt_array($ch, array(
CURLOPT_URL => "https://cloud.aeroqual.com/api/data/AQM65%2017112020-804?from=2021-1-1T00:00:00&to=2021-2-26T00:00:00&averagingperiod=60&includejournal=false",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Cookie: .MONOAUTH=C5PBclbeW29kqexXRGTlXaHImDoLhxR/YzALxc44/SZ+KQV2XuMsZps6OJnXMSi56gjRsQ6ED6GIcH7Fk8XCoJ80IrpsTUDPO+Bmf0tVKaPZtIzpwe7ff3QqBKZLFGZK; ASP.NET_SessionId=9F89912F7F571A228B63ACEC; AWSELB=95CB9B4302EC8CCB93BD1C1D5C4630880B3D9B3CCF1DD49CB392B355F68787785EB0EA72F7A4B7F495B9BA3840A89055C0FDEAE769045026B161BDB6886AF9E5C0388BFFED; AWSELBCORS=95CB9B4302EC8CCB93BD1C1D5C4630880B3D9B3CCF1DD49CB392B355F68787785EB0EA72F7A4B7F495B9BA3840A89055C0FDEAE769045026B161BDB6886AF9E5C0388BFFED;'
),
));
// Do the request
$response = curl_exec($ch);
// Cleanup
curl_close($ch);
echo $response;
?>

我是一名初级网络开发人员,我对Api的并不熟悉,如果我的问题格式不正确,我很抱歉。

在API URL调用中插入可编辑日期和时间的答案是:

<?php
// Date variables for URL
$to = date("Y-m-d", strtotime("now"));
$yesterday = date("Y-m-d", strtotime("-1 day"));
$to_time = date("H:m:s", strtotime("now"));
$yesterday_time = date("H:m:s", strtotime("-1 day"));

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://xxxxxxxxxx/api/data/XXXX65%2017112020-804?from=".$yesterday."T".$yesterday_time."&to=".$to."T".$to_time."&averagingperiod=60&includejournal=false",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Cookie: .MONOAUTH=C5PBclbeW29kqexXRGTlXaHImDoLhxR/YzALxc44/SZ+KQV2XuMsZps6OJnXMSi56gjRsQ6ED6GIcH7Fk8XCoJ80IrpsTUDPO+Bmf0tVKaPZtIzpwe7ff3QqBKZLFGZK; ASP.NET_SessionId=9F89912F7F571A228B63ACEC; AWSELB=95CB9B4302EC8CCB93BD1C1D5C4630880B3D9B3CCF5F0CE3F60EF45F0604C252A119CAE7D802D28AE24434CB392308307A6E5617B4045026B161BDB6886AF9E5C0388BFFED; AWSELBCORS=95CB9B4302EC8CCB93BD1C1D5C4630880B3D9B3CCF5F0CE3F60EF45F0604C252A119CAE7D802D28AE24434CB392308307A6E5617B4045026B161BDB6886AF9E5C0388BFFED'
),
));

$response = curl_exec($curl);
curl_close($curl);

echo $response;

相关内容

  • 没有找到相关文章

最新更新