2

I have a webview in my windows 8 app. Is there a way to access the cookies from the webview? I used cookiecontainer to get response cookies but i would like to get access to cookie jar of the webview. If not possible, can I access local folders?

I found that cookies are stored for each app locally in folder:

Metro App Cookies %Root%\Users\%User%\AppData\Local\Packages\ %MetroAppName%\AC\INetCookies Contains cookie files specific to each Metro App. Data is contained in a text file.

Is there a way to access the contents from the app programatically?

I'll try the following in a bit:

using Windows.Storage;

StorageFolder localFolder = ApplicationData.Current.LocalFolder;

Update: I tried looking for the above folder INetCookies but it doesn't seem to exist.

4

2 回答 2

0

您可以使用本机 InternetGetCookieEx 调用

const int INTERNET_COOKIE_HTTPONLY = 0x00002000;

[DllImport("wininet.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);

static string InternetGetCookieEx(string url)
{
    uint sizeInBytes = 0;
    InternetGetCookieEx(url, null, null, ref sizeInBytes, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero);
    uint bufferCapacityInChars = (uint)Encoding.Unicode.GetMaxCharCount((int)sizeInBytes);
    var cookieData = new StringBuilder((int)bufferCapacityInChars);
    InternetGetCookieEx(url, null, cookieData, ref bufferCapacityInChars, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero);
    return cookieData.ToString();
}
于 2014-07-23T10:41:30.337 回答
0

事实上,如果你去 AppData\Local\Packages\PACKAGE_NAME 文件夹中搜索它,cookie 的文件夹确实存在。但根据 Microsoft 的政策,我们无法访问 PACKAGE_NAME 文件夹中的所有数据。

我们只能访问的文件夹是本地状态、临时状态和永久状态,但 cookie 保存在 AppData\Local\Packages\PACKAGE_NAME\AC\INetCache\SOME_KIND_OF_NAME 文件夹中,该文件夹无法从 Metro 应用程序访问。

如果需要,您可以通过下面的 MSDN 链接获得进一步的许可:

http://msdn.microsoft.com/en-in/library/windows/apps/hh464917.aspx

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.aspx
于 2012-12-18T13:23:21.090 回答