我正在尝试使用下一个代码获取Yahoo日历列表。
$url = "https://calendar.yahoo.com/";
$user = "****@yahoo.com";
$pwd = "*****";
$body = "<A:propfind xmlns:A='DAV:'>
<A:prop>
<A:displayname/>
</A:prop>
</A:propfind>";
$c=curl_init($url);
curl_setopt($c, CURLOPT_HTTPHEADER, array("Depth: 1", "Content-Type: text/xml; charset='UTF-8'", "User-Agent: DAVKit/4.0.1 (730); CalendarStore/4.0.1 (973); iCal/4.0.1 (1374); Mac OS X/10.6.2 (10C540)"));
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($c, CURLOPT_USERPWD, $user.":".$pwd);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PROPFIND");
curl_setopt($c, CURLOPT_POSTFIELDS, $body);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data=curl_exec($c);
curl_close($c);
但作为回应,我有500错误。 有什么想法吗?
我也尝试使用此链接https://caldav.calendar.yahoo.com,但它太过500错误
答案 0 :(得分:0)
这非常简单,如果您查看该页面的源代码,您已经了解了这些隐藏的input
字段:
<input type="hidden" name="sessionId" id="sessionId" value="8nPh4sVBtxEZ">
<input type="hidden" name=".tries" value="1">
<input type="hidden" name=".src" value="yc">
<input type="hidden" name=".md5" value="">
<input type="hidden" name=".hash" value="">
<input type="hidden" name=".js" value="">
<input type="hidden" name=".last" value="">
<input type="hidden" name="promo" value="">
<input type="hidden" name=".intl" value="us">
<input type="hidden" name=".lang" value="en-US">
<input type="hidden" name=".bypass" value="">
<input type="hidden" name=".partner" value="">
<input type="hidden" name=".u" value="336ng15a3fsqq">
<input type="hidden" name=".v" value="0">
<input type="hidden" name=".challenge" value="vrO9R3b_b7Qwm8roug2Ea0jjlIh022jt4w--">
<input type="hidden" name=".yplus" value="">
<input type="hidden" name=".emailCode" value="">
<input type="hidden" name="pkg" value="">
<input type="hidden" name="stepid" value="">
<input type="hidden" name=".ev" value="">
<input type="hidden" name="hasMsgr" value="0">
<input type="hidden" name=".chkP" value="Y">
<input type="hidden" name=".done" value="http://caldav.calendar.yahoo.com/">
<input type="hidden" name=".pd" value="yc_ver=0&c=&ivt=&sg=">
<input type="hidden" name=".ws" id=".ws" value="0">
<input type="hidden" name=".cp" id=".cp" value="0">
<input type="hidden" name="nr" value="0">
<input type="hidden" name="pad" id="pad" value="6">
<input type="hidden" name="aad" id="aad" value="6">
其中一个,你会注意到
<input type="hidden" name=".challenge" value="vrO9R3b_b7Qwm8roug2Ea0jjlIh022jt4w--">
这就是造成&#34; 500错误的原因。&#34;为什么?因为您正在编写机器人/刮刀,并且登录表单使用CSRF protection以及其他防黑客技术。雅虎和所有大家伙都在积极编写代码来阻止你做到这一点。
如果您真的尝试与Yahoo提供的CalDAV协议进行交互,那么您可能需要使用与cURL请求完全不同的方法。可能有some discussion of CalDAV PHP Client libraries out there
答案 1 :(得分:0)
这是我的情况
$xml = "<A:propfind xmlns:A='DAV:'>
<A:prop>
<A:displayname/>
</A:prop>
</A:propfind>";
$url = sprintf("https://caldav.calendar.yahoo.com/dav/%s/Calendar", $email);
$headers = array(
'Depth: 1',
'Content-Type: text/xml; charset=utf-8',
'Content-Length: '.strlen($xml),
"User-Agent: DAVKit/4.0.1 (730); CalendarStore/4.0.1 (973); iCal/4.0.1 (1374); Mac OS X/10.6.2 (10C540)"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $email.":".$password);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PROPFIND');
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($ch);
curl_close($ch);