/// <summary>
/// 获取图片
/// </summary>
public Image Verify(string qqName, out string cookie)
{
item = new HttpItem()
{
URL = "http://captcha.pengyou.com/getimage?&uin=" + qqName + "&aid=15004601&0.11248807175794862",
Method = "GET",
Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*",
Encoding = "utf-8",
ContentType = "application/x-www-form-urlencoded",
UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2; Alexa Toolbar; mxie; .NET CLR 1.1.4322)",
ResultType = ResultType.Byte
};
HttpResult result = http.GetHtml(item);
cookie = result.Cookie;
return byteArrayToImage(result.ResultByte);//得到验证图片
}
public string Login(string qqName, string Password, string Verify,ref string cookie)
{
string str = string.Empty;
str += "u=" + qqName;
str += "&p=" + QQencryption.MD5_QQ_2_Encrypt(long.Parse(qqName),Password, Verify);
str += "&verifycode=" + Verify;
str += "&css=http://imgcache.qq.com/ptcss/b2/qzone/15000101/style.css";
str += "&mibao_css=m_qzone";
str += "&aid=15004601";
str += "&u1=" + System.Web.HttpUtility.UrlEncode("http://www.pengyou.com/index.php?mod=login2&act=qqlogin");
str += "&ptredirect=1";
str += "&h=1";
str += "&from_ui=1";
str += "&fp=loginerroralert";
str += "&ptlang=2052";
str += "&dumy=";
//str += "&login_sig=o2uGOggzs1ppeZD44BwmcEUGyAeC1ZwxDSY-7ftMXgAK10nFbk1cdPiOWBysOlzl";
str += "&action=1-8-14390";
str += "&g=1";
str += "&t=1";
item = new HttpItem()
{
URL = "http://ptlogin2.pengyou.com/login?"+str,
Method = "GET",
Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*",
Encoding = "utf-8",
ContentType = "application/x-www-form-urlencoded",
UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2; Alexa Toolbar; mxie; .NET CLR 1.1.4322)",
Cookie = cookie
};
item.Headersadd("Accept-Encoding", "gzip, deflate");
item.Headersadd("Accept-Language", "zh-CN");
HttpResult result = http.GetHtml(item);
cookie = result.Cookie;
return result.Html;
}
public static class QQencryption
{
public static string MD5_QQ_2_Encrypt(long uin, string password, string verifyCode)
{
ByteBuffer buffer = new ByteBuffer();
buffer.Put(MD5_GetBytes(password));
//buffer.Put(Encoding.UTF8.GetBytes(password));
buffer.PutInt(0);
buffer.PutInt((uint)uin);
byte[] bytes = buffer.ToByteArray();
string md5_1 = MD5_Encrypt(bytes);//将混合后的字节流进行一次md5加密
string result = MD5_Encrypt(md5_1 + verifyCode.ToUpper());//再用加密后的结果与大写的验证码一起加密一次
return result;
}
/// <summary>
/// 获取文本的md5字节流
/// </summary>
/// <param name="md5_str">需要加密成Md5d的文本</param>
/// <returns></returns>
private static byte[] MD5_GetBytes(string md5_str)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(md5_str);
return md5.ComputeHash(bytes);
}
/// <summary>
/// 将字节流加密
/// </summary>
/// <param name="md5_bytes">需要加密的字节流</param>
/// <returns></returns>
private static string MD5_Encrypt(byte[] md5_bytes)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();
byte[] bytes1 = md5.ComputeHash(md5_bytes);
System.Text.StringBuilder stringBuilder = new StringBuilder();
foreach (var item in bytes1)
{
stringBuilder.Append(item.ToString("x").PadLeft(2, '0'));
}
return stringBuilder.ToString().ToUpper();
}
/// <summary>
/// 一次md5加密
///http://www.cnblogs.com/uu102
/// </summary>
/// <param name="md5_str">需要加密的文本</param>
/// <returns></returns>
public static string MD5_Encrypt(string md5_str)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(md5_str);
byte[] bytes1 = md5.ComputeHash(bytes);
System.Text.StringBuilder stringBuilder = new StringBuilder();
foreach (var item in bytes1)
{
stringBuilder.Append(item.ToString("x").PadLeft(2, '0'));
}
return stringBuilder.ToString().ToUpper();
}
}
public class ByteBuffer
{
private byte[] _buffer;
/// <summary>
/// 获取同后备存储区连接的基础流
/// </summary>
public Stream BaseStream;
/// <summary>
/// 构造函数
/// </summary>
public ByteBuffer()
{
this.BaseStream = new MemoryStream();
this._buffer = new byte[0x10];
}
/// <summary>
/// 设置当前流中的位置
/// </summary>
/// <param name="offset">相对于origin参数字节偏移量</param>
/// <param name="origin">System.IO.SeekOrigin类型值,指示用于获取新位置的参考点</param>
/// <returns></returns>
public virtual long Seek(int offset, SeekOrigin origin)
{
return this.BaseStream.Seek((long)offset, origin);
}
/// <summary>
/// 检测是否还有可用字节
/// </summary>
/// <returns></returns>
public bool Peek()
{
return BaseStream.Position >= BaseStream.Length ? false : true;
}
/// <summary>
/// 将整个流内容写入字节数组,而与 Position 属性无关。
/// </summary>
/// <returns></returns>
public byte[] ToByteArray()
{
long org = BaseStream.Position;
BaseStream.Position = 0;
byte[] ret = new byte[BaseStream.Length];
BaseStream.Read(ret, 0, ret.Length);
BaseStream.Position = org;
return ret;
}
#region "写流方法"
/// <summary>
/// 压入一个布尔值,并将流中当前位置提升1
/// </summary>
/// <param name="value"></param>
public void Put(bool value)
{
this._buffer[0] = value ? (byte)1 : (byte)0;
this.BaseStream.Write(_buffer, 0, 1);
}
/// <summary>
/// 压入一个Byte,并将流中当前位置提升1
/// </summary>
/// <param name="value"></param>
public void Put(Byte value)
{
this.BaseStream.WriteByte(value);
}
/// <summary>
/// 压入Byte数组,并将流中当前位置提升数组长度
/// </summary>
/// <param name="value">字节数组</param>
public void Put(Byte[] value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
this.BaseStream.Write(value, 0, value.Length);
}
/// <summary>
/// Puts the int.
/// </summary>
/// <param name="value">The value.</param>
public void PutInt(int value)
{
PutInt((uint)value);
}
/// <summary>
/// 压入一个int,并将流中当前位置提升4
/// </summary>
/// <param name="value"></param>
public void PutInt(uint value)
{
this._buffer[0] = (byte)(value >> 0x18);
this._buffer[1] = (byte)(value >> 0x10);
this._buffer[2] = (byte)(value >> 8);
this._buffer[3] = (byte)value;
this.BaseStream.Write(this._buffer, 0, 4);
}
/// <summary>
/// Puts the int.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="value">The value.</param>
public void PutInt(int index, uint value)
{
int pos = (int)this.BaseStream.Position;
Seek(index, SeekOrigin.Begin);
PutInt(value);
Seek(pos, SeekOrigin.Begin);
}
#endregion
#region "读流方法"
/// <summary>
/// 读取Byte值,并将流中当前位置提升1
/// </summary>
/// <returns></returns>
public byte Get()
{
return (byte)BaseStream.ReadByte();
}
#endregion
}
liujun3233 发表于 2013-6-18 12:16
使用 第二次POST 的cookie 去GET 腾讯的网页,怎么得不到想要的html?
站长苏飞 发表于 2013-4-18 13:51
真是难得给力的帖子啊,强烈支持楼主。
qw8613243 发表于 2013-6-19 11:47
楼主强大,我需要过验证码的。。。QQ:2605173 或者发我邮箱。。。谢谢
qw8613243 发表于 2013-6-19 11:47
楼主强大,我需要过验证码的。。。QQ:2605173 或者发我邮箱。。。谢谢
幻雪丶逆时光 发表于 2013-6-19 08:59
需要提交登录成功的 cookie . GET 参数也必须对 不对的话不行
liujun3233 发表于 2013-6-20 20:04
提交登录成功的cookie不行,因为登录成功的cookie中没有verifysession,GET参数是对的,你不信用登录成功 ...
xmj112288 发表于 2013-7-5 18:48
登陆是成功了,但用获取的cookie去获取其他页的源码,却显示是未登陆的,获取的cookie不能用啊受教了,学习中 ...
欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |