public partial class _Default : System.Web.UI.Page
{
CookieContainer m_cc = new CookieContainer();
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string s;
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("https://passport.baidu.com/?login");
System.Net.ServicePointManager.Expect100Continue = false;
httpReq.Method = "POST";
httpReq.CookieContainer = m_cc;
httpReq.Accept = "*/*";
httpReq.Referer = "http://passport.baidu.com/?login";
httpReq.ContentType = "application/x-www-form-urlencoded";
httpReq.Headers.Add("Accept-Encoding", "gzip, deflate");
httpReq.Headers.Add("Accept-Language", "zh-cn");
httpReq.Headers.Add("Cache-Control", "no-cache");
httpReq.Headers.Add("UA-CPU", "x86");
httpReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)";
string strPostData = GetPostData();
byte[] bsInData =UTF8Encoding.Default .GetBytes(strPostData);
httpReq.ContentLength = bsInData.Length; Stream inputStream = httpReq.GetRequestStream();
inputStream.Write(bsInData, 0, bsInData.Length);
inputStream.Close();
inputStream.Dispose(); HttpWebResponse httpRes = null;
httpRes = (HttpWebResponse)httpReq.GetResponse();
Stream outStream = httpRes.GetResponseStream();
StreamReader sr = new StreamReader(outStream, System.Text.Encoding.GetEncoding("GB2312")); s=sr.ReadToEnd();
sr.Close();
Response.Write(s);
}
private string GetPostData()
{
string strRtn = ""; NameValueCollection nvc = new NameValueCollection();
nvc.Add("aid", "");
nvc.Add("more_param", "");
nvc.Add("need_coin", "");
nvc.Add("need_pay", "");
nvc.Add("next_target", "");
nvc.Add("password", "*****");
nvc.Add("pay_method", "");
nvc.Add("psp_tt", "0");
nvc.Add("return_method", "get");
nvc.Add("return_type", "");
nvc.Add("safeflg", "0");
nvc.Add("skip_ok", "");
nvc.Add("tpl", "mn");
nvc.Add("tpl_ok", "");
nvc.Add("u", "http://www.baidu.com/");
nvc.Add("username", *****");
nvc.Add("verifycode", "");
foreach (string ie in nvc)
{
strRtn += ie + "=" + nvc[ie] + "&";
}
if (strRtn.EndsWith("&"))
strRtn = strRtn.Substring(0, strRtn.Length - 1);
return strRtn; ;
}
}通过post数据实现登录到baidu 为什么却登录不上呢,该怎么实现Post数据中的用户名和密码已经用星号代替问题出在什么地方那个,已经确认我的用户名和密码没有错误
解决方案 »
- 紧急求助??winform 滚动条样式问题??
- 拼音首字母问题。
- 在WPF中如何利用手势(gesture)删除按钮(button)?
- c# datagridview 中的value值为空时如何判断??
- 蜘蛛抓取的初级问题(高手进、在线等)
- c#中用odbc如何连接和操作sqlserver数据库?
- 求DirectX sdk(语音通讯)的下载地址(内含C:\DXSDK\Samples\C#\DirectPlay\VoiceConnect例子)
- 如何获取局域网内其它机器IP地址
- 加了 static到底有什么影响,什么时候用
- 应该如何让程序访问运行该程序机器上的SQL Server?
- 关于窗口的打开
- 探测端口!
httpReq.Headers.Add("Cache-Control", "no-cache");
这2个协议头不是这么添加的吧?