双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

模拟登录阿里联盟,为什么一直提示过期的页面?请大侠帮忙看看!!!!

「已注销」 「已注销」 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
模拟登录阿里联盟,为什么一直提示过期的页面?请大侠帮忙看看!!!!


using System;
using System.Windows.Forms;
using DotNet.Utilities;
using System.Security.Cryptography;
using System.Text;

namespace LoginDemo
{
public partial class Form1 : Form
{
HttpHelper request = new HttpHelper();
public Form1()
{
InitializeComponent();
}

private void btn_login_Click(object sender, EventArgs e)
{
string tbtoken = string.Empty;
HttpItem item = new HttpItem();
item.URL = "http://www.alimama.com/member/minilogin.htm";
HttpResult html = request.GetHtml(item);
tbtoken = GetCookieValue(html.Cookie, "HttpOnly,_tb_token_");
if (string.IsNullOrEmpty(tbtoken))
{
MessageBox.Show("未获取_tb_token的值");
return;
}

string username = txt_user.Text.Trim();
string pwd = txt_pwd.Text.Trim();
string md5pwd = CalculateMD5Hash(pwd).ToLower();
item = new HttpItem();
item.URL = "https://www.alimama.com/member/minilogin_act.htm";
item.Referer = "http://www.alimama.com/member/minilogin.htm";
item.Method = "POST";
item.UserAgent = "User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36";
item.Header.Add("DNT", "1");
item.Cookie = GetLoginCookie(html);
RequestData data = new RequestData();
data.AddField("_tb_token_", tbtoken);
data.AddField("logname", username);
data.AddField("logpasswd", md5pwd);
data.AddField("originalLogpasswd", pwd);
data.AddField("proxy", "");
data.AddField("redirect", "");
data.AddField("style", "");

item.PostDataType = PostDataType.String;
item.Postdata = data.GetData("UTF-8");
item.Allowautoredirect = false;
html = request.GetHtml(item);
rtb_value.Text = html.Html;
}
public string GetLoginCookie(HttpResult html)
{
string s = "";
s = "_tb_token_=" + GetCookieValue(html.Cookie,"HttpOnly,_tb_token_");
s += "; cookie2=" + GetCookieValue(html.Cookie, "cookie2");
s += "; rurl=";
s += "; t=" + GetCookieValue(html.Cookie, "HttpOnly,t");
s += "; v=0";
return s;
}

public string CalculateMD5Hash(string input)
{
// step 1, calculate MD5 hash from input
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);

// step 2, convert byte array to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}

public string GetCookieValue(string cookie, string key)
{
if (string.IsNullOrEmpty(cookie)) return "";
string[] list = cookie.Split(';');
foreach (string s in list)
{
string[] t = s.Split('=');
if (t.Length == 2 && t[0].Equals(key, StringComparison.CurrentCultureIgnoreCase))
{
return t[1];
}
}
return "";
}
}
}



附我写的代码:
http://download.csdn.net/detail/webajax/6570669
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
「已注销」
C# 111,129 成员 642,540 内容