【发布时间】:2019-01-06 15:39:03
【问题描述】:
根据 API 文档,curl 请求应该是:
$data =array ('currentPage' => 1,
'itemsPerPage' => 10
);
$hash = sha1(http_build_query($data) . sha1('password'));
$requestData = array(
'code' => ‘usercode',
'username' => 'username',
'data' => $data,
'hash' => $hash);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://mktp-stage.emag.ro/api-3/vat/read');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($requestData));
$result = curl_exec($ch);
我的应用脚本是:
var headers = {
"Content-Type": "application/json",
"Authorization": "Basic "+ Utilities.base64Encode(user+":"+password)
};
var options = {
"method" : "POST",
"headers" : headers,
"payload" : {
"modifiedAfter" : "2018-12-31 01:00:00",
"status" : 4
}
};
var response = UrlFetchApp.fetch(url,options);
我得到了结果,但没有被“modifiedAfter”过滤:“2018-12-31 01:00:00”, “状态”:4。 我做错了什么?
更新:我使用了 Dimu Designs 示例,但结果仍未过滤。 他们(API 所有者)说我应该像 curl 请求一样在数组中发送过滤器,因为 API 不接受 json 请求,但只返回 json 格式:
$data =
array (
'currentPage' => 1,
'itemsPerPage' => 10
);
$hash = sha1(http_build_query($data) . sha1('password'));
$requestData = array(
'code' => ‘usercode',
'username' => 'username',
'data' => $data,
'hash' => $hash);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($requestData));
谢谢!
【问题讨论】: