在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