java获取httponly_获取 httponly 的 cookie

///

/// WinInet.dll wrapper

///

internal static class CookieReader

{

///

/// Enables the retrieval of cookies that are marked as "HTTPOnly".

/// Do not use this flag if you expose a scriptable interface,

/// because this has security implications. It is imperative that

/// you use this flag only if you can guarantee that you will never

/// expose the cookie to third-party code by way of an

/// extensibility mechanism you provide.

/// Version: Requires Internet Explorer 8.0 or later.

///

private const int INTERNET_COOKIE_HTTPONLY = 0x00002000;

[DllImport("wininet.dll", SetLastError = true)]

private static extern bool InternetGetCookieEx(

string url,

string cookieName,

StringBuilder cookieData,

ref int size,

int flags,

IntPtr pReserved);

///

/// Returns cookie contents as a string

///

///

///

public static string GetCookie(string url)

{

int size = 512;

StringBuilder sb = new StringBuilder(size);

if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero))

{

if (size < 0)

{

return null;

}

sb = new StringBuilder(size);

if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero))

{

return null;

}

}

return sb.ToString();

}

}


版权声明:本文为weixin_42245967原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。