一步一步做,肯定能成功 HttpHelper类请从网络上搜索
string postData = getPostData();
HttpHelper ht = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
Method = "POST",
Postdata = postData,
CookieContainer = new System.Net.CookieContainer(),
ContentType = new MiLoginHttpHelper().contentType,
};
string html = ht.GetHtml(item).Html;
方法:getPostData()
private string getPostData()
{
string name = txtUName.Text.Trim();
string pwd = txtPwd.Text.Trim();
PostParaPair model = new PostParaPair();
model.Add(new PostParaPair() { Key = "_sign", Value = "R4cRs0JL2JfHHaPenjPG2c3Foa4=" });
model.Add(new PostParaPair() { Key = "callback", Value = "https://account.xiaomi.com/sts?sign=6aRtWvCpNNuCwNpKtdu9CEEJOL8%3D&followup=https%3A%2F%2Faccount.xiaomi.com%2Fpass%2FuserInfo&sid=passport" });
model.Add(new PostParaPair() { Key = "qs", Value = "%3Fcallback%3Dhttps%253A%252F%252Faccount.xiaomi.com%252Fsts%253Fsign%253D6aRtWvCpNNuCwNpKtdu9CEEJOL8%25253D%2526followup%253Dhttps%25253A%25252F%25252Faccount.xiaomi.com%25252Fpass%25252FuserInfo%2526sid%253Dpassport%26sid%3Dpassport" });
model.Add(new PostParaPair() { Key = "pwd", Value = pwd });
model.Add(new PostParaPair() { Key = "serviceParam", Value = "{\"checkSafePhone\":false}" });
model.Add(new PostParaPair() { Key = "sid", Value = "passport" });
model.Add(new PostParaPair() { Key = "user", Value = name });
return model.ToString();
}
类PostParaPair:
public class PostParaPair
{
List<PostParaPair> paraList = new List<PostParaPair>();
public string Key { get; set; }
public string Value { get; set; }
public void Add(PostParaPair para)
{
paraList.Add(para);
}
public override string ToString()
{
string reString = "";
if (paraList.Count != 0)
{
foreach (PostParaPair item in paraList)
{
reString += string.Format("&{0}={1}", item.Key, CommonMethod.GetUrlEncode(item.Value));
}
}
return reString.TrimStart(‘&‘);
}
}
CommonMethod.GetUrlEncode:方法
public static string GetUrlEncode(string content)
{
return System.Web.HttpUtility.UrlEncode(content, System.Text.Encoding.UTF8);
}