Simulate two clicks using httpclient C# and pass PKI Certificate

Viewed 62

Using a client, I want to login to a webpage using PKI certificate. On the website, I would need to agree to an acknowledgement by clicking on a checkbox, then the login button will be enabled to see and then I can click on that. From there, a window will popup for me to select a certificate and input a password and then I can log in.

On a different website, I was able to press the agree button by doing this:

using (var client = new HttpClient())
{
     var content = new FormUrlEncodedContent(new Dictionary<string, string> { { "value", "agree" } });
     var agreementPost = await client.PostAsync(url, content);
}

where 'value' is the element of "input" in html and 'agree' is in between the quotes for the value tag.

For the website I'm working on, the input tag is under several div's, but the tag looks like this:

<input id="agree_cb" type="checkbox" click="handleOnClick(this);">

and for the button I press after that, it looks like this:

<button value="X509"></button>

So my code is this:

X509Certificate2 cert = GetCertificate();
HttpClientHandler handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ClientCertificates.Add(cert);

HttpClient client = new HttpClient(handler);
var content = new FormUrlEncodedContent(new Dictionary<string, string> 
{ 
    { "id", "agree" },
    { "value" , "X509"} 
});
var agreementPost = await client.PostAsync(entry_url, content);

var connectionEntry = await client.GetAsync(main_URL);
var output = await connectionEntry?.Content.ReadAsStringAsync();

But when I output it, it outputs the html page as if it never logged in. I'm not sure if I am clicking the buttons or not. I know the PKI certificate is being passed into the client, but I don't know if the timing of it, is correct or not?

Any help is appreciated

0 Answers
Related