English 中文(简体)
为什么使用互联网SetCookie在网络Broser控制下建立厨师的守则没有发挥作用?
原标题:Why this code using InternetSetCookie to set cookies at a WebBroser control is not working?

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

而Fidller说的是我寄来的:

“entergraph

象每个人都利用这一职能一样,但对于我来说,我无法工作。 我用不同的电脑进行审判,也失败了。 任何帮助都是巨大的。

最佳回答

我发现,问题不是检查行动的结果。 www.nonold.com不是一个有效的《国际仲裁裁决汇编》,它必须是

问题回答

Just came across this myself.For completeness, you need to check the value returned from InternetSetCookie and if false, call GetLastError which would have given you a return code of 87 - invalid parameter.

i.e.

[DllImport("kernel32.dll")]
public static extern uint GetLastError();

......

bool ok = SetWinINETCookieString("www.nonexistent.com", "dataToTest", "thisIsTheData");
if (!ok)
{
  int errorCode = GetLastError(); //this will return 87  for www.nonexistent.com
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签