Filling out a web form programatically in c#

81 views Asked by At

I have a web application that fills out some information into text boxes and hits a button. I am now trying to turn it into an app for a smart device running Windows CE. My code is as follows:

string doc = webBrowser1.DocumentText;
HtmlElement userValue = doc.GetElementById("username");
userValue.SetAttribute("value", "devacc");
HtmlElement passValue = doc.GetElementById("password");
passValue.SetAttribute("value", "zzq15354");
HtmlElement subButton = doc.GetElementById("submit");
subButton.InvokeMember("click");

Is there a way I can do this so it will run in Windows CE?

Post Request:

string postData = "?username=uname&password=pass";
byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
var req = (HttpWebRequest)WebRequest.Create("https://api.surveymonkey.net/oauth/" + postData);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
req.ContentLength = dataBytes.Length;
using (Stream stream = req.GetRequestStream())
{
     stream.Write(dataBytes, 0, dataBytes.Length);
}
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
string s = new StreamReader(response.GetResponseStream()).ReadToEnd();

Edit: I'm thinking I'll do it with a post request, but I'm still confused on how I'll pass in the username/password

Edit x2: I've included what I have so far of the post request. I'm not sure if I'm missing anything but I think that postData is wrong.

0

There are 0 answers