C#如何使用geckofx浏览器浏览帖子数据? [英] C# How to Navigate with post data using the geckofx browser?
问题描述
我在Visual Studio 2013中使用C#,并与geckofx浏览器一起使用,我需要使用POST进行导航. Navigate方法告诉我我需要一个MimeInputStream,使用起来很直观.我面临的问题是如何初始化它? MimeInputStream没有构造函数.我发现下面的代码可以编译,除了不能将GeckoMIMEInputStream强制转换为MimeInputStream的部分.我的代码是:
I'm using C# with Visual Studio 2013, working with the geckofx browser, and I need to Navigate using POST. The Navigate method is telling me I need a MimeInputStream, which is intuitive to use. The problem I'm facing with that is how to initialize it? MimeInputStream doesn't have a constructor. I found that the following code compiles, except the part where it can't cast the GeckoMIMEInputStream into a MimeInputStream like that. My code is:
string dataString = string.Format("username={0}&pwd={1}, Username, Password);
GeckoMIMEInputStream postData = new GeckoMIMEInputStream();
postData.AddHeader("Content-Type", "application/x-www-form-urlencoded");
postData.AddContentLength = true;
postData.SetData(dataString);
myGeckoFXBrowser.Navigate("javascript:void(document.getElementById('formname').submit())", GeckoLoadFlags.ReplaceHistory, null, postData);
推荐答案
感谢汤姆,这使我朝正确的方向前进;这是我的生产代码:
Thanks Tom, that sent me to the right direction; here is my production code:
protected void NavigateWithPostData(string URLToGoTo, string POSTData)
{
var postData = MimeInputStream.Create();
postData.AddHeader("Content-Type", "application/x-www-form-urlencoded");
postData.AddContentLength = true;
postData.SetData(POSTData);
mainBrowser.Navigate(URLToGoTo, GeckoLoadFlags.BypassCache, mainBrowser.Url.AbsoluteUri, postData);
}
然后像这样使用它:
string dataString = string.Format("SMNTH={0}&SDAY={1}&SYR={2}", workingDate.Month, workingDate.Day, workingDate.Year);
NavigateWithPostData("http://<yourapp>", dataString);
这篇关于C#如何使用geckofx浏览器浏览帖子数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!