PHP curls with Microsoft Dynamics CRM 2011

I am trying to extract some data from Microsoft Dynamics CRM 2011 Online that is on a remote host; it works if I manually (from a browser) log into the system and execute mine from my server, which runs PHP on the Linux host, but, of course, I want to authenticate and run CRUD operations without my mediation :).

But he continues to show me "The object has moved here." pages for authentication. If I set CURLOPT_FOLLOWLOCATION => 1, it will display the crm login page.

If anyone can offer any clue to resolve the situation ... thanks!

<?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);
+3
source share
3 answers

da problem ntml, , CRM JSON.

$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 , , .

+2

Does adding the following CURL option help?

CURLOPT_HTTPAUTH => CURLAUTH_NTLM

This is a trick for me. Apparently the server I'm connecting to does not support basic HTTP authentication, but supports NTLM. You can help in your case.

+1
source

All Articles