Hey there I need to enter in some text into web text fields using a C# program.
Basically for my own personal use I've developed a desktop facebook chat application (which I may release as freeware since everyone hates the web chat).
This application works great but I开发者_高级运维 need to somehow take log a person in via the program, this is the bit that stifles me, anyone have any solutions?
my current idea is to have a form for the username and password which then puts the information in a webBrowser control within the program in the appropriate fields.
Any help would be greatly appreciated :)
You need to create a POST request to the server to log the user in.
To do this you need to use the System.Net.WebRequest
class, this excellent article describes how to use it.
To figure how exactly how to construct the request, use Fiddler to capture it when you log into your own account. Using this you can construct an identical request using WebRequest
- except substitute the username / password where necessary.
This is the only real way you can achieve this.
I would suggest logging in with a POST request as well, but since you are already using a webBrowser control (correct?) then you can use code such as this:
webBrowser1.Document.All.GetElementsByName("email")[0].SetAttribute("Value", textBox1.Text);
webBrowser1.Document.All.GetElementsByName("pass")[0].SetAttribute("Value", textBox2.Text);
webBrowser1.Document.GetElementsByTagName("form")[0].InvokeMember("submit");
That will login to facebook just fine.
Also consider looking at XMPP libs, such as http://code.google.com/p/jabber-net/
Facebook chat supports the XMPP protocol so you can get rid of a lot of the hard work and just worry about making the front-end look nice for the user.
To login to XMPP via facebook its your facebook_username@chat.facebook.com and your facebook password.
精彩评论