早上好,
我正在尝试使用php CURL脚本在Microsoft Dynamics NAV 365中创建一个主导实体。但是我的CURL响应中不断收到“HTTP错误401 - 未经授权:访问被拒绝”。但是,我可以通过网络界面创建一个领先优势。
我已根据MSDN文档网站上的说明从lead entity type创建了我的对象。
以下是我的代码:
$lead = array('person' =>
array(
'topic' => 'WEB LEAD',
'name' => $fullname,
'firstname' => $firstname,
'lastname' => $lastname,
'companyname' => $company,
'telephone1' => $telephone,
'emailaddress1' => $email,
'description' => $comment,
),
);
$dynamics = $url . '/api/data/v8.2/leads';
$ch = curl_init($dynamics);
$options = array(
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json; charset=utf-8',
'OData-MaxVersion: 4.0',
'OData-Version: 4.0',
'Accept: application/json',
),
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_USERPWD, 'username:password',
CURLOPT_POSTFIELDS => json_encode($lead),
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$responseInfo = curl_getinfo($ch);
curl_close($ch);
答案 0 :(得分:0)
您需要先从AAD获取授权令牌
获得所有令牌后,您需要在请求http标头
中添加授权CURLOPT_HTTPHEADER => array(
'Content-Type: application/json; charset=utf-8',
'OData-MaxVersion: 4.0',
'OData-Version: 4.0',
'Accept: application/json',
'Authorization: <put the token here completly with name>',
),