开发者

Filling a HTML form with C#

I need help with connecting to a certain website via my username & password.

With WebClient I can fill the username field and the password field, but how do I invoke the click method of the button?

And How can I fill a specific textBox 开发者_高级运维that doesn't have an ID?

I tried doing this with webBrowser, but every time I navigate I have to use a new function every time, which makes the work much harder.

Thanks.


What you're trying to do is wrong. If you want to Post some data to a web address (a URL), simply create a web form (a simple HTML form), fill it, and then send it. Just consider these notes:

  1. Your HTML's form action should be the exact URL of the form you're imitating.
  2. Your input controls should have the same name attribute value.

For more information, see Form Spoofing


Look at the web browser control and see if you can use that inside your windows form to perform the task that you are doing. Once you are satisfied with the results, you can make the web browser control invisible, and it'll work just like you do with web response and request calls.


View the source code and find the id of the button (say "Login"). Then use:

HtmlElement elem = webBrowser1.Document.GetElementById("Login");
if (elem != null)
    elem.InvokeMember("click");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜