《小C QQ空間轉帖、分享工具》之QQ空間數據傳遞的g_tk算法(C#)

原文地址:http://user.qzone.qq.com/419067339/2cookie

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) post

{
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值了.url

Form1.caozuo.臨時傳遞TK值 = hash.ToString();
}
resp.Close();
return respHTML;
}orm

用法:GET_HTTP(URL, 來路, "*/*", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)", false, new CookieContainer(),Cookies編號(由於我使用到了多帳號));string

相關文章
相關標籤/搜索