我正在尝试从位于远程主机上的Microsoft Dynamics CRM 2011 Online中提取一些数据; 它是有效的,如果我manualy(从浏览器)登录并执行我的服务器在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);
答案 0 :(得分:2)
我解决了问题,通过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>";
}
如果有人知道如何在休息终点进行crud操作,请告诉我。
答案 1 :(得分:1)
我担心我已经回答了我自己的问题,我想要实现的目标是不可能的,因为这样: 只能在应用程序中进行身份验证。
如上所述:
http://msdn.microsoft.com/en-us/library/gg334279
我正在尝试从远程站点进行身份验证。
答案 2 :(得分:1)
添加以下CURL选项有帮助吗?
CURLOPT_HTTPAUTH => CURLAUTH_NTLM
它为我做了伎俩。显然,我连接的服务器不支持基本的HTTP身份验证,但强制执行NTLM。在你的情况下可能会有所帮助。