我必須在網頁上實現表單,並在發送數據時將數據發送到Microsoft Dynamics CRM。數據需要保存到一定的領先地位。Microsoft Dynamics CRM和PHP/JSON
我已經創建了簡單的PHP腳本,它使用curl與CRM服務器通信,但我總是得到401
狀態碼,指示授權失敗。
define('MS_CRM_URL', 'https://______.crm.dynamics.com/');
define('MS_CRM_USER', '[email protected]');
define('MS_CRM_PASS', 'password');
$method = '/api/data/v8.0/accounts?$select=name&$top=3';
$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_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);
}
echo '<pre>';
var_dump($status_code);
var_dump($json);
echo '</pre>';
$method
var內容取自我在Microsoft文檔站點某處找到的示例。文檔對我來說不是很有幫助。