为什么使用InternetSetCookie在WebBroser控件上设置cookie的代码不起作用?

Ign*_*cia 5 .net c# browser cookies

我已经完成了这个示例,试图理解为什么我不使用我的WebBrowser发送cookie,这很简单,表单上有一个WebBrowser,就是这样:

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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这就是Fidller所说的我发送的内容:

在此输入图像描述

看起来每个人都使用这个功能成功,但对于我的生活,我无法让它工作.我尝试过不同的计算机,但也失败了.任何帮助都会很棒,谢谢.

Ign*_*cia 1

我发现了,问题出在没有检查操作结果。www.nonexistent.com 不是有效的 URI,它必须是http://www.nonexistent.com