I want to import dates from iCal that provides AirBnb. I am developing ASP.NET MVC app with some nugget called iCal.Net.
The code:
public ActionResult Index()
{
const string airbnbCalendar = "https://www.airbnb.com/calendar/ical/1111111.ics?s=zkdjhfkjsdzkhfkkjsadjkfhskjdfhjk";
Calendar calendar;
using (var client = new WebClient())
{
byte[] file = null;
file = client.DownloadData(airbnbCalendar);
Stream stream = new MemoryStream(file);
calendar = Calendar.Load(stream);
}
return View();
}
I am getting an error on line client.DownloadData(airbnbCalendar):
The remote server returned an error: (403) Forbidden
I've googled a little bit, and I found that for some reason I must "imitate" a web browser for that request. Here is the link to the airbnb forum
How can I transform my request to the CURL request? In order to airbnb gives me proper data?
P.S. When I copy airbnb url to the browser, I get proper .ics file
For security reason I've altered url address.
The User-Agent
is transferred via request-header. So add an appropriate header to the webclient like shown here.