问题
I have a simple program that i can open a webpage and i paste the user name and password from textbox1
then do something inside, after that a want to re-login with another account
i can do it for tow or three accounts put i want to deal with an open number of usernames
i want to take usernames from a Multiline textbox
the code to paste only the first line and the pass word and click ok is:
TextReader read = new StringReader(textBox2.Text);
int rows = 500;
string[] text1 = new string[rows];
for (int r = 1; r < rows; r++)
{
text1[r] = read.ReadLine();
// textBox3.Text = text1[r];
HtmlElement ele = webBrowser1.Document.GetElementById("name"); if (ele != null)
ele.InnerText = text1[r];
ele = webBrowser1.Document.GetElementById("password"); if (ele != null)
ele.InnerText = text1[r] + "5";
ele = webBrowser1.Document.GetElementById("s1"); if (ele != null)
ele.InvokeMember("click");
text1[r] means that it will take the just the first line
now the program is inside then logout with this code
webbrowser1.navigate("http://example.com/logout.php");
then i want to re login and do the same put with the second line (another account) then the third etc. How can i do it?
回答1:
It doesn't quite work like that. What you need to do is behave like the browsers, namely, submit the form:
- How do you programmatically fill in a form and 'POST' a web page?
- How to submit http form using C#
You will have to study the structure of the POST request and build a similar post request with your application. You'll have to use something like FireBug to investigate the network traffic that's generated when you submit the form and duplicate the POST request. Take a look at this question too: http form post change submit data
来源:https://stackoverflow.com/questions/12786547/how-to-make-the-browser-login-and-do-something-then-re-login-with-another-accoun