0

I want to read from a text file line by line and enter each line into a online box to see if it works.

For example:

bob
tom
rob

I want to read from that and enter it into, say my websites username or password box and enter and see if it works.

I believe you are suppose to send a request to your webhost or whatever but I do not know how.

foreach(string line in File.ReadAllLines("your text file"))
{
// send request here to your webhost
}

Please say if I am not clear.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

Use the WebClient Class.

string string loginData = "username=***&passowrd=***";

WebClient wc = new WebClient();

wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5");
wc.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
wc.Headers.Add("Accept-Encoding", "identity");
wc.Headers.Add("Accept-Language", "en-US,en;q=0.8");
wc.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
wc.Headers.Add("ContentType", "application/x-www-form-urlencoded");
string response = wc.UploadString("http://xyz.com/accounts/login/", "POST", loginData);
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Thanks Jeremy, what does the middle chunk of the code mean? (After new webclient and before string response) –  Feb 22 '13 at 05:27
0

From what I understand you want to read username and password from a textfile and populate the login page with values from the file and validate it. (Please correct me if I am wrong)

One way in which you can do is,

1 - Once the page loads, send an ajax call and read that text file using StreamReader (How to)

2 - Send usernames and passwords (list) back to the ajax call as result and use that value to populate the text fields, one at a time.

3 - Test with one set of username and password to see if it works, continue till you get the right combination. Preferabably keep a log of which all combination worked and which didnt.

Hope this helps

EDIT :

@zerushamebo Just looked at Jeremy's answer, do you want to crawl/scrape a website ? Is that your question, if YES, here is a read for you

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
  • @zerushamebo Just looked at Jeremy's answer, do you want to crawl/scrape a website ? Is that your question, if YES, [here is a read for you](http://yassershaikh.com/introduction-to-web-scraping-with-httpwebrequest-using-asp-net-mvc3/) – Yasser Shaikh Feb 22 '13 at 05:59