使用ASP.net登录其他网站

本文关键字:其他 网站 登录 net ASP 使用 | 更新日期: 2023-09-27 17:59:54

我尝试了很多次使用httprequest,但都不起作用。。。这是我的代码

//POSTDATA=inputUserName=dmsang&inputPassword=123456789
string strURL;
string strPostData = "";
string strResult;
HttpWebResponse webrespond;
HttpWebRequest webresquest;
StreamReader sr;
StreamWriter sw;
//======================================
//string a = form1.FindControl("chogochu");
//set url to post
strURL = "http://up.4share.vn/?act=login";
//post some data        
strPostData = "inputUserName=dmsang&inputPassword=123456789";
webresquest = (HttpWebRequest)WebRequest.Create(strURL);
webresquest.Method = "POST";
webresquest.Referer = strURL;
webresquest.ContentType = "application/x-www-form-urlencoded";
webresquest.ContentLength = strPostData.Length;
//post data
sw = new StreamWriter(webresquest.GetRequestStream());
sw.Write(strPostData);
sw.Close();
//read the returned data
webrespond = (HttpWebResponse)webresquest.GetResponse();
sr = new StreamReader(webrespond.GetResponseStream());
strResult = sr.ReadToEnd();
sr.Close();
//write the result
TextBox1.Text = strResult;

如果响应标头中的位置=/?act=accinfo是成功登录

使用ASP.net登录其他网站

您必须检查响应(strResultwebrespond.Headers)以查看错误是什么。问题应该显示在其中的某个位置,您的发现将决定下一步需要采取的步骤。