简体   繁体   中英

Login to the other Website using ASP.net

i tried many times using httprequest but not working... here my code

//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;

if Location in Response Header = /?act=accinfo is Login Successful

You will have to examine the response ( strResult and webrespond.Headers ) to see what the error is. The problem should be shown somewhere in there, and what you find will determine what step you need to take next.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM