0

Fetch SharePoint RSS with PHP using cURL for parsing

The SharePoint instance that I needed to get an RSS feed out of was behind an https layer. To accomplish this task, I used cURL to fetch the list. In addition, I needed cURL to not verify the security certificate on the site. Before you begin, you will need the URL to the SharePoint list (see $url below).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Settings
$url = "https://my.sharepoint.com/sites/mysite/_layouts/listfeed.aspx?List=listid";
$user = "username";
$pass = "password";
 
//Open file to be written to
$temp_file = "/path/to/feed.xml";
$fp = fopen($temp_file, 'w');
 
//Initialize a cURL session
$curl = curl_init();
 
//Return the transfer as a string of the return value of curl_exec() instead of outputting it out directly
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
//The URL to fetch
curl_setopt($curl, CURLOPT_URL, $url);
 
//Force HTTP version 1.1
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
 
//Use NTLM for HTTP authentication
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
 
//Username/password to use for the connection
curl_setopt($curl, CURLOPT_USERPWD, $user . ':' . $pass);
 
//Stop cURL from verifying the peer's certification
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 
//Execute cURL session
$result = curl_exec($curl);
 
//Close cURL session
curl_close($curl);
 
fwrite($fp, $result);
fclose($fp);

I then use PHP’s simplexml_load_file() for parsing.

Norbert Krupa

Technical Consultant

Leave a Reply

Your email address will not be published. Required fields are marked *