doqw89029 2017-12-18 10:42
浏览 41

未经授权:从PHP在线访问Web API Dynamics 365

I'm trying to call the Dynamics CRM 365 online using PHP, but I keep getting the same error:

Error: failed with status 401, response HTTP Error 401 - Unauthorized: Access is denied , curl_error

This is my code

define('MS_CRM_URL', 'https://xxxx.crm4.dynamics.com');
define('MS_CRM_USER', 'xxxxx@xxxxx.onmicrosoft.com');
define('MS_CRM_PASS', 'xxxxxxxx');
$method = '/api/data/v8.2/contacts';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, MS_CRM_URL . $method);
curl_setopt($ch, CURLOPT_USERPWD, MS_CRM_USER .':'. MS_CRM_PASS);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(

));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept' => 'application/json',
    'OData-MaxVersion' => '4.0',
    'OData-Version' => '4.0',
    'Content-Type' => 'application/json',
));

$server_output = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

$json = array();
if ((int)$status_code === 200) {
    $json = json_decode($server_output);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 高价求中通快递查询接口
    • ¥15 解决一个加好友限制问题 或者有好的方案
    • ¥15 关于#java#的问题,请各位专家解答!
    • ¥15 急matlab编程仿真二阶震荡系统
    • ¥20 TEC-9的数据通路实验
    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?