开发者

cURL Authentication Problems Datatel R25 XML Feed

I am still fairly new at playing with PHP. I wanted to poke at a small project. I have the ability to access an xml feed from our calendar system at work. The feed requires authentication with a username and password. I am trying to automate pulling this feed. My hope is to one day use it to automate the scheduling of another system but for now I'm 开发者_运维问答just trying to get this side working.

I have read through some of the cURL documentation on php.net. I have also searched through stackoverflow for a few examples. They were helpful in getting me started but not much further. Below is what I have so far. But all I get back is:

UNAUTHORIZED The request requires authorization

So I'm racking my head to figure out what might be the issue. Part of my problem I'm sure is my ignorance with the actual process behind what is going on between the client and server. When I interact with it normally I just go to the feed URL, the browser prompts me for a username and password, and then after putting that in it gives me an xml page.

I've checked for most of the formatting errors and syntax errors I knew to look for. That may still be it but at this point I think it's more my lack of understanding how it all fits together. Thanks for any help.

Similar issues:

Parsing XML data with Namespaces in PHP

CURL HTTP Authentication at server side

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://somesight.someplace.edu/r25ws/servlet/wrd/run/events.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>


I figured it out on my own after looking at a similar tutorial for Twitter. I tried a different approach to formatting the options and it worked fine. I also cut down on the number of options I was sending because it seemed like overkill. Code that works below.

<?php
$username = 'myusername';
$password = 'mypassword';

$datecall = curl_init("http://somesite.someplace.edu/r25ws/servlet/wrd/run/events.xml");

curl_setopt($datecall, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($datecall, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($datecall);
echo $result;

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜