[C#] 纯文本查看 复制代码
HttpHelper http = new HttpHelper();
HttpItem ite ...[/quote]
以下是登录成功的代码:
[mw_shl_code=csharp,true]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SetHttp;
using csharp中执行js方法;
using System.Text.RegularExpressions;
using System.Net;
namespace 测试
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txtUser_Enter(object sender, EventArgs e)
{
getVecode();
}
private string JS(){
script_run.ScriptEngine myscript = new script_run.ScriptEngine(script_run.ScriptLanguage.JavaScript);
object result = myscript.Eval("getSession()","function getSession(){return Math.random().toString();}");
return result.ToString();
}
/// <summary>
/// 获取验证码
/// </summary>
private void getVecode() {
string url = "https://account.meilishuo.com/Register/Captcha?token=asde39ad9&session=" + JS();
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = url,
Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5",
Referer = "https://account.meilishuo.com/user/login",
Cookie = cookie,
ResultType = ResultType.Byte
};
HttpResult result = http.GetHtml(item);
string statusCodeDescription = result.StatusDescription;
Image img = Json.byteArrayToImage(result.ResultByte);
pictureBox1.Image = img;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
getVecode();
}
string cookie = string.Empty;
string nt = string.Empty;
private void butLogin_Click(object sender, EventArgs e)
{
txtLog.Text += "\r\n" + Login(cookie) + "\r\n";
}
private string Login(string cookie) {
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem() {
URL = "https://account.meilishuo.com/aw/user/logon",
Method = "POST",
Referer = "https://account.meilishuo.com/user/login",
UserAgent = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko",
ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
Cookie =cookie,
Accept = "application/json, text/javascript, */*; q=0.01",
Postdata = "login_name="+txtUser.Text.Trim().Replace("@","%40")+"&password="+txtPwd.Text.Trim()+"&nt="+nt+"&checkcode="+txtVcode.Text.Trim()+"&save_state=1"
};
//item.Header.Add("nt", nt);
//item.Header.Add("X-Requested-With", "XMLHttpRequest");
//item.Header.Add("DNT", "1");
HttpResult result = http.GetHtml(item);
return result.Html;
}
/// <summary>
/// 获取nt值
/// </summary>
/// <returns></returns>
public string GetNt(out string cookie) {
cookie = string.Empty;
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem() {
URL = "http://www.meilishuo.com/welcome",
ResultCookieType = ResultCookieType.CookieCollection
};
HttpResult result = http.GetHtml(item);
cookie = "MEILISHUO_GLOBAL_KEY=" + result.CookieCollection["MEILISHUO_GLOBAL_KEY"].Value;
cookie += ";santorini_mm=" + result.CookieCollection["santorini_mm"].Value;
cookie += ";SEASHELL=" + result.CookieCollection["SEASHELL"].Value;
cookie += ";numInCart=0;LOGON_FROM=http%3A%2F%2Fwww.meilishuo.com%2Fwelcome";
string nt = Regex.Match(result.Html.Replace(" ", ""), @"nt:'([\S]+)?',").Groups[1].Value;
return nt.Replace("+","%2B").Replace("/","%2F");
}
private void Form1_Load(object sender, EventArgs e)
{
nt = GetNt(out cookie);
txtLog.Text += "\r\n" + nt + "\r\n" + cookie + "\r\n";
}
}
}