I want to parse a html page. But I can only read this html page when I authenticated on the server. But with my current code, there come's that I am not logged in. Here is my current code:
// This functions start when I click a button
private void BtLog_Click(object sender, RoutedEventArgs e)
{
string url = "https://subcard.subway.co.uk/de_cardholder/servlet/SPLoginServlet";
StringBuilder body = new StringBuilder();
body.Append("language=" + "de");
body.Append("&user=" + tbUser.text);
body.Append("&password=" + pbPassword.Password);
body.Append("&transIdentType=" + "1");
body.Append("&programID=" + "6");
bool isNetwork = NetworkInterface.GetIsNetworkAvailable();
if (!isNetwork)
{
}
else
{
try
{
WebClient webClient = new WebClient();
webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded"; // Your Application Header Content-Type
webClient.Encoding = Encoding.UTF8;
webClient.UploadStringAsync(new Uri(url), "POST", body.ToString(), null);
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("https://subcard.subway.co.uk/de_cardholder/JSP/SPSummary.jsp"));
}
catch
{
MessageBox.Show("Error");
}
}
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result.ToString());
// If the I am logged in and got the string I want to parse it, but first the other thing have to work
}
I thought I have to work with cookiecontainer, but I don't know how this works. Thanks for any advice or solutions for my problem!!