即使通过设置所有必需的标题和选项,我也无法使用cURL更新联系人记录。来自cURL的响应为空,cur_error()也没有显示任何错误。
任何人都可以在下面的代码中提出错误的建议吗?
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
curl_close($curl);
答案 0 :(得分:0)
这应该有效,确保正确构造参数并添加Content-Type
标题:
$data = array(
"GivenName" => "test",
"Surname" => "contact",
"Title" => "",
"CompanyName" => "",
"BusinessPhones" => array("2132323")
);
$params = json_encode($data);
$headers = array(
"User-Agent: Office365Integration/1.0",
"client-request-id: $client_id",
"return-client-request-id: FALSE",
"Authorization: Bearer $access_token",
"Accept: application/json",
"odata.metadata: full",
"Content-Type: application/json"
);
$url = "https://outlook.office365.com/api/v1.0/me/contacts/$contact_id";