I want to send an HTTP Post request to a website in order to log in and get some data from another page which requires an authorized user.
So when I run the following code I get a 403 forbidden status.
static async void GetHtmlAnswer()
{
var values = new Dictionary<string, string>
{
{ "userName", "myUsername" },
{ "pwd", "myPassword" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("fromURL", content);
var responseString = await response.Content.ReadAsStringAsync();
var answer = await client.GetStringAsync("secondPageURL");
Console.WriteLine(responseString);
}
The variable response is from the first page that contains the login form and the variable answer is desired html code that requires login.
Note: My credentials are right and I can login properly.
Any ideas what should I do?