postautomationrequesthttp-postwatin

Sending POST Requests in Watin


I am trying to do send a POST request on a web page with Basic Authentication. So is there any samples showing how to automate sending POST Requests in Watin


Solution

  • I found that this post works

    IE _ie = new IE();
    object flags = null;
    object targetFrame = null;
    object headers = "Content-Type: application/x-www-form-urlencoded" + Convert.ToChar(10) + Convert.ToChar(13);
    object postDataBytes = ASCIIEncoding.ASCII.GetBytes("{ mydata: 5 }");
    object resourceLocator = "http://google.com";
    IWebBrowser2 browser = (IWebBrowser2)_ie.InternetExplorer;
    browser.Navigate2(ref resourceLocator, ref flags, ref targetFrame, ref postDataBytes, ref headers);
    _ie.WaitForComplete();
    

    My document is a json response and I'm still working on getting access to its raw contents via WatiN - currently it is being prompted to download.