[转载]《小C QQ空间转帖、分享工具》之QQ空间数据传递的g_tk算法(C#) – dapeng888 – 博客园.
原文地址:http://user.qzone.qq.com/419067339/2
public string GET_HTTP(string url, string referer_post, string accept_post, string useragent_post, bool keepalive, CookieContainer CookieContainer_Post,int i) { System.Uri httpposturl = new System.Uri(url); HttpWebRequest reqp; reqp = WebRequest.Create(url) as HttpWebRequest; reqp.Method = "GET"; reqp.Referer = referer_post; reqp.Accept = accept_post; reqp.UserAgent = useragent_post; reqp.CookieContainer = CookieContainer_Post; HttpWebResponse resp = reqp.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default); string respHTML = reader.ReadToEnd(); if (reqp.CookieContainer != null) { Form1.caozuo.User_Cookies[i] = reqp.CookieContainer; string shuju = ""; foreach (Cookie cookie in resp.Cookies) { shuju += cookie.Name + "-" + cookie.Value;//获取所有的Cookies值 } string str = shuju.Substring(shuju.IndexOf("skey-") + 5, 10);//提取skey-后面的10个字符用于算出g_tk值 long hash = 5381; for (int o = 0; o < str.Length; o++) { hash += (hash << 5) + str[o]; } hash = hash & 0x7fffffff;//hash就是算出的g_tk值了. Form1.caozuo.临时传递TK值 = hash.ToString(); } resp.Close(); return respHTML; }
用法:
GET_HTTP(URL, 来路, “*/*”, “Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)”, false, new CookieContainer(),Cookies编号(因为我使用到了多账号));