zoukankan      html  css  js  c++  java
  • 《小C QQ空间转帖、分享工具》之QQ空间数据传递的g_tk算法(C#)

    原文地址: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编号(因为我使用到了多账号));

  • 相关阅读:
    C#文件操作常用相关类(Directory类、File类、Path类)
    winform使用相对路径读取文件的方法
    设置GridView不换行强制GridView不换行GridView强制不换行
    VS2010 Visual Studio2010 保护视力 背景色设置颜色设置
    20190306
    20190325
    常用DOS命令
    项目创建
    VS2015自定义工具栏,往工具栏上添加按钮
    ping不通公网ip时路由器设置
  • 原文地址:https://www.cnblogs.com/niaowo/p/3970859.html
Copyright © 2011-2022 走看看