java gecko cookie,那可能吗 ? GeckoFX可以使用每个实例单独的CookieContainer?

I'm Using Geckfx22.0 and xulrunner22.0. Since GeckoWebBrowser in .Net shares cookies with all other instances of GeckoWebBrowsers I would like for a GeckoWebBrowser to have it's own cookie container which doesn't share any cookies that was created previously in other GeckoWebBrowsers or other instances.

For example when I create a GeckoWebBrowser it shouldn't have any cookies. And when I run 2 instances of GeckoWebBrowser they have their own cookie container and don't share or conflict cookies with each other.

How is that possible?

I've tried various possible ways by creating different class and initiating geckofx but when running different browser at same time it sharing cookies among other browsers. If i remove cookies from one browser , the same happening for other browsers too. I have initiated the proxy and useragent at different times and its works but cant apply various useragents for multiple browsers at the same time.

public void Initiate()

{

Gecko.Xpcom.Initialize(AppDomain.CurrentDomain.BaseDirectory + "/xulrunner");

if (this.IsProxySet)

{

Gecko.GeckoPreferences.User["network.proxy.http"] = this.Host;

Gecko.GeckoPreferences.User["network.proxy.http_port"] = this.Port;

Gecko.GeckoPreferences.User["network.proxy.type"] = 1;

}

if (IsUseragentSet)

{

Gecko.GeckoPreferences.User["general.useragent.override"] = this.Useragent;

}

}

And to remove cookies i'm using following code :

nsICookieManager CookieMan;

CookieMan = Xpcom.GetService("@mozilla.org/cookiemanager;1");

CookieMan = Xpcom.QueryInterface(CookieMan);

CookieMan.RemoveAll();

Help will be appreciated !!!

解决方案

You could possibly try implementing your own cookie manager that supports this:

This code is currently untested and may contain typeos

This code requires a geckofx version newer than v22.0-0.6

[Guid("c375fa80-150f-11d6-a618-0010a401eb10")]

[ContractID(TestCookieServiceFactory.ContractID)]

public class TestCookieServiceFactory

: GenericOneClassNsFactory

{

public const string ContractID = "@mozilla.org/cookieService;1";

}

public class TestCookieService : nsICookieService

{

// Implement nsICookieService...

}

public void Main()

{

Xpcom.Initialize("My Xulrunner/Fireofox location");

var existingFactoryDetails = TestCookieServiceFactory.Unregister();

TestCookieServiceFactory.Register();

var browser = new GeckofxWebBrowser();

// Add browser to form etc...

browser.Navigate("http://SomeWebPageThatUsesCookies")

// Cookie requests should now be sent to TestCookieService, process them as your want.

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值