Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outlook ICS failed to open stream: HTTP request failed! #311

Closed
roelVerdonschot opened this issue Jun 14, 2022 · 13 comments
Closed

Outlook ICS failed to open stream: HTTP request failed! #311

roelVerdonschot opened this issue Jun 14, 2022 · 13 comments

Comments

@roelVerdonschot
Copy link
Contributor

  • PHP Version: 7.4 & 8.1
  • PHP date.timezone: Europe/Amsterdam
  • ICS Parser Version: 2.1.19 & 3.1.1
  • Mac/Linux

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:

  1. Add outlook ICS link
  2. Run
@u01jmg3
Copy link
Owner

u01jmg3 commented Jun 14, 2022

Please fill in the issue template in full - I'm unable to investigate your issue without this

@roelVerdonschot
Copy link
Contributor Author

roelVerdonschot commented Jun 14, 2022

What more do you need?

How to download ICal link?

  1. Create outlook account/Open https://outlook.live.com/calendar/
  2. In right top press the gear-icon
  3. Search for share
  4. Open Share agenda/Share calendar
  5. Copy link

@gafderks
Copy 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);

@roelVerdonschot
Copy link
Contributor Author

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)';

@u01jmg3
Copy link
Owner

u01jmg3 commented Jun 14, 2022

You can already define a custom user agent: 205afb3

@roelVerdonschot
Copy link
Contributor Author

roelVerdonschot commented Jun 14, 2022

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.

@u01jmg3
Copy link
Owner

u01jmg3 commented Jun 14, 2022

Feel free to raise a PR

@annervisser
Copy link

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);

roelVerdonschot pushed a commit to roelVerdonschot/ics-parser that referenced this issue Jun 16, 2022
@roelVerdonschot
Copy link
Contributor Author

@u01jmg3 I created a PR

@SamLNL
Copy link

SamLNL commented Jul 15, 2022

I'm still receiving "failed to open stream: HTTP request failed! HTTP/1.1 400". Any updates on this issue?

@u01jmg3
Copy link
Owner

u01jmg3 commented Jul 15, 2022

The code is not yet released. Watch out for v3.2.0 or use dev-master in the meantime.

@u01jmg3
Copy link
Owner

u01jmg3 commented Jul 15, 2022

@SamLNL: see v3.2.0

@SamLNL
Copy link

SamLNL commented Jul 18, 2022

@u01jmg3 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants