I’ve done this sample to try to understand why I’m not sending cookies at all with my WebBrowser, it’s pretty simple, the form has a WebBrowser on it, that’s all:
namespace BrowserTest
{
public partial class Form1 : Form
{
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool InternetSetCookie(string url, string name, string data);
public static bool SetWinINETCookieString(string url, string name, string data)
{
return Form1.InternetSetCookie(url, name, data);
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// None of two works
//SetWinINETCookieString("www.nonexistent.com", null, "dataToTest=thisIsTheData");
SetWinINETCookieString("www.nonexistent.com", "dataToTest", "thisIsTheData");
this.webBrowser1.Navigate("www.nonexistent.com");
}
}
}
And that’s what Fidller says I’m sending:

Looks like everyone using this function succeeds but for the life of me that I cannot get it working. I’ve tried at different computers and it fails there too. Any help will be great, thanks.
I found it, the problem was not checking the result of the operation. http://www.nonexistent.com is not a valid URI, it has to be http://www.nonexistent.com