PHP curl与Microsoft Dynamics CRM 2011交谈
作者:互联网
我试图从驻留在远程主机上的Microsoft Dynamics CRM 2011 Online中提取一些数据;
如果我手动(从浏览器)登录并从在Linux主机上运行PHP的服务器上执行我的服务器,它将起作用,但是我当然希望在没有中介的情况下进行身份验证和运行CRUD操作:).
但是它继续向我显示“对象已移至此处”.认证页面.
如果我设置CURLOPT_FOLLOWLOCATION => 1,显示crm的登录页面.
如果有人可以提出解决问题的任何线索……谢谢!
<?php
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$urlValue = "/LeadSet?$select=Address1_City,FirstName,LastName";
$username = "domain\user";
$pass = "pass";
$handle = curl_init();
curl_setopt_array($handle,
array (
CURLOPT_USERAGENT => $useragent,
CURLOPT_USERPWD => $username . ':' . $pass,
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_URL => 'https://myhost.com/xrmservices/2011/OrganizationData.svc',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $urlValue,
CURLOPT_RETURNTRANSFER => true,
)
);
$response = curl_exec($handle);
curl_close($handle);
header('Content-Type: text/plain;');
print_r($response);
解决方法:
我解决了通过ntml进行身份验证的问题,此代码显示了如何以JSON格式从CRM检索联系人.
$url='http://<server_adress>/organizationName/XRMServices/2011/OrganizationData.svc/ContactSet';
$ch = curl_init();
$headers = array(
'Method: GET',
'Connection: keep-alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: application/json; charset=utf-8',
'Accept: application/json',
'Host <server network adress>');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, '<user>:<password>');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
//echo $response;
$array=json_decode($response, true);
$size=count($array['d']['results']);
echo "Numero de registos:".$size."<p>";
echo "Contactos:<p>";
for($i=0;$i<$size;$i++){
echo "Nome: ". $array['d']['results'][$i]['FullName']."<p>";
echo "Cidade: ". $array['d']['results'][$i]['Address1_City']."<p>";
echo "Emprego: ". $array['d']['results'][$i]['JobTitle']."<p>";
echo "Morada: ". $array['d']['results'][$i]['Address1_Name']."<p>";
echo "Telefone: ". $array['d']['results'][$i]['Address1_Telephone1']."<p>";
echo "Email: ". $array['d']['results'][$i]['EMailAddress1']."<p>";
echo "Pais: ". $array['d']['results'][$i]['Address1_Country']."<p>";
echo "Codigo-postal: ". $array['d']['results'][$i]['Address1_PostalCode']."<p>";
echo "Criado por: ". $array['d']['results'][$i]['CreatedBy']['Name']."<p>";
echo "...................................................................................<p>";
}
如果有人知道如何在剩余端点中进行粗操作,请告诉我.
标签:rest,curl,dynamics-crm,odata,php 来源: https://codeday.me/bug/20191101/1982672.html