visual-studiopostgeckogeckofxnavigateurl

C# How to Navigate with post data using the geckofx browser?


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

Solution

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