//取当前webBrowser登录后的Cookie值
[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);
//取出Cookie,当登录后才能取
private static string GetCookieString(string url)
{
// Determine the size of the cookie
int datasize = 256;
StringBuilder cookieData = new StringBuilder(datasize);
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
{
if (datasize < 0)
return null;
// Allocate stringbuilder large enough to hold the cookie
cookieData = new StringBuilder(datasize);
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
return null;
}
return cookieData.ToString();
}之前我写过篇关于C# HttpWebRequest 绝技的文章 无视证书的方法请在篇文章里面查找谢谢,以下不做无视证书的方法
无论是Get还是Post 带Cookie,编码问题解决 ,这里完全做到了无视编码的问题
最近把上面的方法整理了一下,这个类相当于一个SqlHelper类一下,我把它叫做HttpHelper类,以后还会慢慢更新,希望大家多我支持,
给大家分享一下吧,不好的地方感谢大家留言指正,不多说了上代码吧!
/// <summary>
/// 类说明:HttpHelps类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式
/// 编码日期:2011-08-20
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.IO.Compression;
public class HttpHelps
{
#region 预定义方法或者变更
&n |