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

private static string GetCookieString(string url)
{
    int datasize = 256;
    StringBuilder cookieData = new StringBuilder(datasize);
    if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
    {
        if (datasize < 0)
            return null;
        cookieData = new StringBuilder(datasize);
        if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
            return null;
    }
    return cookieData.ToString();
}

标签: 技术, C#

添加新评论