请教(新浪模拟登录)

haojuntu haojuntu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

http://topic.csdn.net/u/20110827/22/d0c63b1f-4c28-48df-98b3-1fc5187d9f5d.html
大家帮忙看一下吧,代码如下,可是不能登录成功啊,先谢谢了。。

 private void SinaLogin_Load(object sender, EventArgs e)
{
string username = "";
string password = "";
string url = "http://login.sina.com.cn/sso/prelogin.php?entry=miniblog&callback=sinaSSOController.preloginCallBack&user=" + username + "&client=ssologin.js(v1.3.12)";
url = GetUrl(url);
try
{
if (!string.IsNullOrEmpty(url))
{
int a = url.LastIndexOf(',') - 10;
int b = url.LastIndexOf(':') + 2;
string servertime = url.Substring(a, 10);
string nonce = url.Substring(b, 6);
string Pwd1 = GetPwd(password);
string Pwd2 = GetPwd(Pwd1);
string Pwd3 = GetPwd(Pwd2 + servertime + nonce);
string login = @"http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.12)&service:miniblog&client:ssologin.js%28v1.3.12%29&entry:miniblog&encoding:utf-8&gateway:1&savestate:0&useticket:1&username:" + username + "&servertime:" + servertime + "&nonce:" + nonce + "&pwencode:wsse&password:"+Pwd3+"&url:http://www.baidu.com&returntype:META&ssosimplelogin:1";
string result = GetUrl(login);
}
else
{
Console.WriteLine("出错了!");
}
}
catch (Exception)
{

throw;
}


}
static string GetPwd(string Pwd)
{
byte[] data = System.Text.Encoding.Default.GetBytes(Pwd);//以字节方式存储
System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] result = sha1.ComputeHash(data);//得到哈希值
return System.BitConverter.ToString(result).Replace("-", ""); //转换成为字符串的显示
}

private string GetUrl(string url)
{
string _str = string.Empty;
WebRequest request = WebRequest.Create(url);

request.Timeout = 5000;
//request.Method = "POST";
try
{
WebResponse response = request.GetResponse();

StreamReader reader = new StreamReader(response.GetResponseStream(),System.Text.Encoding.GetEncoding("gb2312"));
_str = reader.ReadToEnd();
reader.Close();
reader.Dispose();
response.Close();

}
catch (System.Net.WebException ex)
{
//tb.Text = ex.Message;
}
return _str;
}
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
haojuntu
.NET社区 62,272 成员 668,968 内容