I have to need scrap data from a secure (https) website after login and show this data to my MVC5 application. It is very easy to scrap data from a unsecured web site after login as i have done using following method:
public async Task<ActionResult> Index()
{
HttpClient client = new HttpClient();
var values = new Dictionary<string, string>
{
{ "User.UserName", "abc" },
{ "User.Password", "abc" }
};
var content = new FormUrlEncodedContent(values);
client.BaseAddress = new Uri("http://abc1.com/Account/Login");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
var response= await client.PostAsync("http://abc1.com/Account/Login", content);
HttpResponseMessage response1 = await client.GetAsync("http://abc1.com/user/Index"); // This page data was reqired
var responseString = await response1.Content.ReadAsStringAsync();
ViewBag.LogedIn = responseString;
return View();
}
After this i got the next page data in view bag as my requirement. But in case of Https website it is not working and also no error occurs.
Please suggest me what changes i should do within this method so that it also Login for a secured website.
Thanks in advance.