Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Web Page Login Automation using c#

Posted on 2004-04-06
6
Medium Priority
?
1,521 Views
Last Modified: 2012-06-21
Hello,
I have a list of the domains that I own and a stats program running on the server that tracks the traffic for each domain (i.e. www.mydomain.com/stats would direct me to the stats page).  I have been writing web data mining crawlersfor a couple months now so I am familiar with HTML parsing, etc..., but I cannot figure out how to automate the login/pass box that my server pops up when navigating to my stats pages.  I have set up my data structures with each of my domains and their appropriate login and pass, now I just have to get them into the text fields and click the button.  Any help is appreciated ahead of time.  THanks,
TCash
0
Comment
Question by:TCash11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:TCash11
ID: 10768004
Point Increase, Thanks Again
TCash
0
 
LVL 10

Accepted Solution

by:
Kavar earned 2000 total points
ID: 10771822
string pc;
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new NetworkCredential(Uname, UPass);
pc  = Encoding.ASCII.GetString(wc.DownloadData(<your web url here>));
0
 

Author Comment

by:TCash11
ID: 10778615
thanks Kavar, a few tweaks(actually only that networkcredential setup line), and my code worked great.  Much appreciated.
TCash
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:TCash11
ID: 10779554
Out of curiosity, my follow up question is what if there is a login and pas box on the page itself (or any textbox for that matter) as opposed to the popup authentication box; how do you enter text into a textbox on an web page from the c# program?  It may come in handy when creating crawlers in the future.  Thanks
TCash
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10781026
use the document object model... (document.all("<control Name>").text= )

just wondering what did you change?
0
 

Author Comment

by:TCash11
ID: 10784632
----Here is my function; I had everything except the request.Credentials line
private string getHTML(string address)
            {
                  string html = "";
                  System.Net.WebRequest request;
                  System.Net.WebResponse response;
                  try
                  {
                        statusBar1.Text = "Getting HTML for Address: " + address;
                        request = System.Net.WebRequest.Create(address);
                        request.Credentials = new NetworkCredential("login", "pass");
                        response = request.GetResponse();
                        byte [] buffer = new byte[1024];
                  
                        while(response.GetResponseStream().Read(buffer,0,buffer.Length) != 0)
                        {
                              html += System.Text.Encoding.ASCII.GetString(buffer);

                        }
                  }
                  catch
                  {
                        statusBar1.Text = "exception getting html";
                        MessageBox.Show("Error Getting HTML");
                  }
                  return html;
            }

-------Haven't played with the document object yet , but thanks for the response.  
-TCash
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress

618 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