"The remote server returned an error: (400) Bad Request when downloading outlook.office365.com and outlook.live.com ical/ics file using WebRequest.Create()

John Yim 11 Reputation points
2022-06-09T23:27:27.367+00:00

I'm getting "The remote server returned an error: (400) Bad Request" when trying to download outlook.office365.com and outlook.live.com ical/ics file using WebRequest.Create(). For example:

var outlook = "https://outlook.office365.com/owa/calendar/1553ff8f8cbf4066b750e3727958f281@masked/46044022e24c45469dee6721bf92c6374486754768175751168/calendar.ics";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(outlooklive);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
myResponse.Close();

However it works for google and icloud calendar.
Any idea why?

Developer technologies | C#
{count} vote

1 answer

Sort by: Most helpful
  1. John Yim 11 Reputation points
    2022-06-10T08:20:10.18+00:00

    Found the fix: need to have something in the header User-Agent

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.