lundi 23 mars 2015

how to POST to sharepoint 2013 using php curl



at work we have sharepoint 2013 on-premise. currently no one is experienced about it so I'm trying to learn it. at this point I need to get some data from sharepoint lists using php/linux.


I end up with the code below which works fine and gets list items. YES I know it's not safe to send user and pass like this but like I said I'm still learning.



$url = "http://mydomain/_api/web/lists/GetByTitle('CustomList')/Items";
$loginDomain = "DOMAIN";
$loginUser = "username";
$loginPass = "password";
$login = $loginDomain . "/" . $loginUser . ":" . $loginPass;
$mycurl = curl_init();
curl_setopt($mycurl, CURLOPT_HEADER, 0);
curl_setopt($mycurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($mycurl, CURLOPT_URL, $url);
curl_setopt($mycurl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($mycurl, CURLOPT_USERPWD, $login);
curl_setopt($mycurl, CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1');
curl_setopt($mycurl, CURLOPT_HTTPHEADER,array('Accept: application/json;odata=verbose'));
curl_setopt($mycurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($mycurl, CURLOPT_SSL_VERIFYHOST, FALSE);
$webResponse = curl_exec($mycurl);


But with this method I can't use GetItems it says



The HTTP method 'GET' cannot be used to access the resource 'GetItems'


I tried to add following line but didn't work.



curl_setopt($mycurl,CURLOPT_POST, 1);


any idea how can I fix this so I can use GetItems








0 commentaires:

Enregistrer un commentaire