Reputation: 1901
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.
Upvotes: 2
Views: 548
Reputation: 846
I added request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36";
to my HttpWebRequest
object in order to download iCal data from AirBnb
Upvotes: 0
Reputation: 1459
This is specifically what I added and it worked:
webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Upvotes: 0
Reputation: 949
The User-Agent
is transferred via request-header. So add an appropriate header to the webclient like shown here.
Upvotes: 2