在c#中以编程方式填写Web表单

时间:2014-01-06 19:05:21

标签: c# windows-ce http-post smart-device

我有一个Web应用程序,可以将一些信息填入文本框并点击按钮。我现在正试图将其变成运行Windows CE的智能设备的应用程序。我的代码如下:

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");

我有没有办法可以在Windows CE中运行它?

张贴申请:

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();

编辑:我想我会用帖子请求来做,但我仍然对如何传递用户名/密码感到困惑

编辑x2:我已经包含了目前为止的帖子请求。我不确定我是否遗漏了任何东西,但我认为postData是错误的。

0 个答案:

没有答案