Closed roelVerdonschot closed 2 years ago
Please fill in the issue template in full - I'm unable to investigate your issue without this
What more do you need?
How to download ICal link?
I had the same issue. It seems that Outlook is returning a 400 status because a User-Agent header is missing when the iCal is requested.
I resolved this by downloading the iCal through cURL and then using initString
.
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://outlook.office365.com/owa/calendar/...");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_USERAGENT, $agent);
$calendar_data = curl_exec($curl);
curl_close($curl);
$ical = new \ICal\ICal(false, [
'defaultWeekStart' => 'MO'
]);
$ical->initString($calendar_data);
Thx @gafderks
With the modification below or a way to set the userAgent via the constructor would be a better fix.
protected $httpUserAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
You can already define a custom user agent: https://github.com/u01jmg3/ics-parser/commit/205afb3
Ye but thats not via the constructor. The best fix would be is to add 'httpUserAgent' to the $configurableOptions. Or add the agent as default bc everybody that uses outlook links would need this.
Feel free to raise a PR
The issue seems to be related to the Host header, not the user-agent header.
We've currently worked around this by downloading the file using Guzzle and then passing it to ICal with initString
:
use GuzzleHttp\Client as GuzzleClient;
use ICal\ICal;
$iCalFile = (new GuzzleClient())->get($iCalUrl)->getBody()->getContents();
$iCal = new ICal(false, []);
$iCal->initString($iCalFile);
@u01jmg3 I created a PR
I'm still receiving "failed to open stream: HTTP request failed! HTTP/1.1 400". Any updates on this issue?
The code is not yet released. Watch out for v3.2.0
or use dev-master
in the meantime.
@u01jmg3 thanks!
7.4 & 8.1
Europe/Amsterdam
2.1.19 & 3.1.1
Description of the Issue:
When adding an outlook ICS link I get the PHP error failed to open stream: HTTP request failed! HTTP/1.1 400
Steps to Reproduce: