Reputation: 630
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);
Upvotes: 1
Views: 3694
Reputation: 1
I know it's been a long time, but I am experiencing the same issue :
var postData = MimeInputStream.Create();
I have a classic "system.NullReferenceException", no constructor for MimeInputStream as said before...
Upvotes: 0
Reputation: 630
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);
}
Then use it like:
string dataString = string.Format("SMNTH={0}&SDAY={1}&SYR={2}", workingDate.Month, workingDate.Day, workingDate.Year);
NavigateWithPostData("http://<yourapp>", dataString);
Upvotes: 2
Reputation: 6709
I haven't actually tried this, but:
var postData = MimeInputStream.Create();
postData.AddHeader("Content-Type", "application/x-www-form-urlencoded");
postData.AddContentLength = true;
postData.SetData(dataString);
Upvotes: 1