在C ++中从默认浏览器中读取cookie

[英]Reading cookies from default browser in C++


I want to create a c++ application that works together with a website. In order to keep the application synchronized with the website I want to be able to read some cookies from the user's default browser. Is there any way to do this?

我想创建一个与网站一起工作的c ++应用程序。为了使应用程序与网站保持同步,我希望能够从用户的默认浏览器中读取一些cookie。有没有办法做到这一点?

3 个解决方案

#1


Not in the general sense - there's no real defined format for cookie storage, so each browser is free to keep the cookie database wherever, and in whatever style, it prefers.

不是一般意义上的 - 没有真正定义的cookie存储格式,因此每个浏览器都可以自由地将cookie数据库保存在任何地方,以及它所喜欢的任何风格。

You could implement cookie reading functions for the mainstream browsers (IE, Firefox), but that would leave some people out. It would also be non-robust - what happens when the user clears their cookie cache, or uses more than one browser?

您可以为主流浏览器(IE,Firefox)实现cookie读取功能,但这会让一些人离开。它也是非强健的 - 当用户清除其cookie缓存或使用多个浏览器时会发生什么?

If you want to keep your application synchronised with a website, I'd recommend that you have it call directly into web services (RESTful, etc) on that site, with a username/identifier your application users configure. This way, you're not tied to an arbitrary 3rd party that is, at best, only "maybe" right.

如果您希望让您的应用程序与网站保持同步,我建议您直接调用该站点上的Web服务(RESTful等),并使用您的应用程序用户配置的用户名/标识符。这样,你就不会被任意第三方所束缚,最好只是“可能”正确。

#2


Yes, fairly trivial. Define a webservice http://example.com/capturecookie?tracking-guid. It returns the cookie sent the last time for that GUID. From you application, pick a random guid. Call that webservice with your random GUID first in the default browser (See other S.O. topics for that) and then with the same GUID from inside your application. The second time, you'll get back the cookies from the first.

是的,相当微不足道。定义Web服务http://example.com/capturecookie?tracking-guid。它返回上次为该GUID发送的cookie。从您的应用程序中,选择一个随机的guid。首先在默认浏览器中使用随机GUID调用该Web服务(请参阅其他S.O.主题),然后使用应用程序内部的相同GUID。第二次,你将从第一次获取cookie。

Note that the exact notion of "cookies of a webbrowser" is necessarily imprecise. For instance, my default webbrowser (Opera) is set to drop all cookies when it exists, except cookies from whitelisted sites. So whether example.com has cookies depends a lot on whether Opera is running.

请注意,“webbrowser的cookie”的确切概念必然是不精确的。例如,我的默认Web浏览器(Opera)设置为删除所有cookie,除了来自列入白名单的网站的cookie。因此,example.com是否有cookie取决于Opera是否正在运行。

#3


Firefox stores all its cookies in cookies.txt: http://www.velocityreviews.com/forums/t10844-cookies-in-firefox.html

Firefox将所有cookie存储在cookies.txt中:http://www.velocityreviews.com/forums/t10844-cookies-in-firefox.html

For the "default browser", you're going to have to write custom code for the number of different browsers out there, but it's certainly not possible. See: http://www.aboutcookies.org/Default.aspx?page=2#ie7 for a start, and get googling!

对于“默认浏览器”,您将不得不为不同浏览器的数量编写自定义代码,但这肯定是不可能的。请参阅:http://www.aboutcookies.org/Default.aspx?page = 2#ie7开始,并获取谷歌搜索!


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/05/01/a0932fda71c8016b6336db4dc25744c1.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com