无法使用 cURL 更新 office365 联系人
Unable to update office365 Contacts using cURL
即使设置了所有必需的 headers 和选项,我也无法使用 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);
这应该有效,确保参数构造正确并添加 Content-Type
header:
$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";
即使设置了所有必需的 headers 和选项,我也无法使用 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);
这应该有效,确保参数构造正确并添加 Content-Type
header:
$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";