【基础】用 HttpWebRequest 模拟csdn登录 问题

SqlServer2008 2010-12-30 10:04:04

protected void Button1_Click(object sender, EventArgs e)
{
string url = "http://passport.csdn.net/UserLogin.aspx?from=http://community.csdn.net/";
string zh = TextBox1.Text;//账号
string mm = TextBox2.Text;//密码
string yzm = TextBox3.Text;//验证码

string postdata = "";


//请求
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(url);

hwr.Referer = "http://passport.csdn.net/UserLogin.aspx?from=http://community.csdn.net/";
hwr.ContentType = "application/x-www-form-urlencoded";
hwr.ContentLength = postdata.Length;
hwr.Method = "POST";
hwr.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19 (.NET CLR 3.5.30729)";
hwr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
hwr.CookieContainer = this._cookies;

Stream requestStream = hwr.GetRequestStream();
StreamWriter writer = writer = new StreamWriter(requestStream);
writer.Write(postdata);


writer.Flush();
writer.Close();
requestStream.Close();

//响应
HttpWebResponse response = (HttpWebResponse)hwr.GetResponse();//

string qqurl=response.ResponseUri.ToString();//获取返回相应的url



}


每次运行到 HttpWebResponse response = (HttpWebResponse)hwr.GetResponse(); 这句代码时就报错,
报 “远程服务器返回错误: (500) 内部服务器错误。”
...全文
145 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jcx396158820 2010-12-31
  • 打赏
  • 举报
回复
上面的都说没了。。
SqlServer2008 2010-12-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wuyq11 的回复:]

http://topic.csdn.net/u/20100604/18/fadb1e99-e010-4aad-9e4f-bf5f0f745ee1.html
[/Quote]

谢谢,明天看看
SqlServer2008 2010-12-30
  • 打赏
  • 举报
回复
csdn 说我有非法字符,所以只能截图发上来了
SqlServer2008 2010-12-30
  • 打赏
  • 举报
回复
string postdata 的值如图:

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧