.net – Windows Phone WebBrowser设置cookie

我使用HttpWebRequest进行REST服务,它使用一些依赖于JSESSIONID cookie的基本身份验证.我需要将该cookie传递给Webbrowser控件以重用该会话,但没有找到任何可用的解决方案,允许我在浏览器的cookie存储区中传递该cookie.

有什么办法吗?我现在能想到的唯一方法是使用Naviagate(url,null,MANUALLY_CONSTRUCTED_HEADER),这是一种蛮力.

是的,并且必须使用Webbrowser进行此类操作.

有什么建议么?

一个想法是,您可以通过 JavaScript添加cookie.您应该能够这样做(如果您的浏览器控件上IsScriptEnabled为true):
private void setCookie(string name,string value,string path = "",string domain = "",bool isSecure=false,string expires = "")
{
        var sb = new StringBuilder();
        sb.AppendFormat("document.cookie = '{0}=\" + escape(\"{1}\")",name,value);
        if (!String.IsNullOrEmpty(expires))
            sb.AppendFormat(";expires=\"{0}\"",expires); // should be a GMTString
        if (!String.IsNullOrEmpty(path))
            sb.AppendFormat(";path=\"{0}\"",path); 
        if (!String.IsNullOrEmpty(domain))
            sb.AppendFormat(";domain=\"{0}\"",domain);
        if (isSecure)
            sb.Append(";secure'");
        var cookieJs = sb.ToString();
        Debug.WriteLine(cookieJs);
        webbrowser.InvokeScript(cookieJs);
}

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...