Solved

Automatically log into a website in webbrowser component

Posted on 2010-08-22
7
546 Views
Last Modified: 2013-11-27
how to auto logon a site in a webbroswer component. What code will auto populate the username, password input boxes and autoclick the login button?

HTML looks like this:-

<form class="ccform" action="login.php" method="post" onsubmit="login();">
<fieldset>
<legend>Login</legend>
<span class="errormsg-inline"></span>
<div class="field-row">
<label for="username">Username</label>
<input type="text" class="field" name="username" id="username" maxlength="16" value="" tabindex="1" />
</div>
<div class="field-row">
<label for="password">Password</label>
<input type="password" class="field" name="password" id="password" maxlength="16" tabindex="2" />
</div>
<div class="field-row">
<input type="hidden" name="direct" id="direct" value="yes" />
<input type="hidden" name="redirect" value="" />
<input type="submit" class="button-inline" name="submit" value="Login" tabindex="3" />
</div>
<div class="field-row">
<p><a href="public.php?mode=forgot" tabindex="4">I forgot my username or password</a></p>
</div>
</fieldset>
</form>
0
Comment
Question by:Oli999
7 Comments
 
LVL 9

Expert Comment

by:Snarfles
ID: 33494895
Is this your own site or someone elses? and how are you opening it?
0
 
LVL 5

Expert Comment

by:kawzaki
ID: 33495040
create a POST request to the http://www.example.com/login.php

and that will do it for you.

details

Basically, you would need to do the following:
1. create a HttpWebRequest object and use HttpWebRequest.Method = "POST".
2. set the Post data to contain your data (username and password).
3. "Post" (i.e. execute and get the response for) the HttpWebRequest.


and you will face cookie not enabled issue, so make sure you enable it as described first line in the code below...

CookieContainer cookies = new CookieContainer();
HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(site);
postRequest.CookieContainer = cookies; // note this
postRequest.Method = "POST";
postRequest.ContentType = "application/x-www-form-urlencoded";
using (Stream stream = postRequest.GetRequestStream())
{
    stream.Write(buffer, 0, buffer.Length);
}


good luck!
0
 
LVL 2

Author Comment

by:Oli999
ID: 33497276
it's someone else's site and I'm just using webbrowser1.navigate to open it
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497676
Using IWebBrowser2 is a good idea to do this task.
0
 
LVL 9

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497683
0
 
LVL 9

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497689
             If u need the complete code, plz let me know!
                                             
0
 
LVL 2

Accepted Solution

by:
Oli999 earned 0 total points
ID: 33575610
Thanks all for your suggestions. Have figured this one out myself now though.

here's how I did it.
If (WebBrowser1.Document.All("username") IsNot Nothing) And (WebBrowser1.Document.All("password") IsNot Nothing) Then
            WebBrowser1.Document.All("username").SetAttribute("value", "username")
            WebBrowser1.Document.All("password").SetAttribute("value", "password")
            For Each element As HtmlElement In WebBrowser1.Document.Body.All
                If element.Name = "submit" Then
                    If element.GetAttribute("value") = "Login" Then
                        element.InvokeMember("click")
                    End If
                End If
            Next
        End If

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question