如何在PHP API Curl中添加正文过滤器

piv4azn7  于 2023-02-11  发布在  PHP
关注(0)|答案(2)|浏览(94)

我需要在我的API curl的PHP代码中添加一些过滤器的正文内容我该怎么做
我需要添加到我的API调用中
下面是API调用代码

$chn = curl_init();
curl_setopt($chn, CURLOPT_POST, true);
curl_setopt($chn, CURLOPT_URL, 'https://api.livechatinc.com/v3.4/agent/action/list_archives');
curl_setopt($chn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chn, CURLOPT_POSTFIELDS, '{}');
curl_setopt($chn, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Bearer ' . $token
    )
);
dwthyt8l

dwthyt8l1#

$parameters = array( "key1" => val1, "key2" => val2);

# your curl definition

curl_setopt($chn, CURLOPT_POSTFIELDS, $parameters);
8cdiaqws

8cdiaqws2#

通过在CURLOPT_POSTFIELDS选项中以字符串形式传递数据,可以将请求正文添加到API调用中。

$filter = array(
"page" => 1,
"page_size" => 20,
"start_time" => "2022-01-01T00:00:00Z",
"end_time" => "2022-12-31T23:59:59Z",
"sort_by" => "start_time",
"sort_order" => "asc"
);

$chn = curl_init();
curl_setopt($chn, CURLOPT_POST, true);
curl_setopt($chn, CURLOPT_URL, 'https://api.livechatinc.com/v3.4/agent/action/list_archives');
curl_setopt($chn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chn, CURLOPT_POSTFIELDS, json_encode($filter));
curl_setopt($chn, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $token
)
);

相关问题