469,964 Members | 1,662 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

login to website from code

i use the following code to login to a website

but i dont achieve my purpose

can anybody help me on this

//code to request the page

webRequest = HttpWebRequest.Create(url) as HttpWebRequest;

webRequest.Proxy = proxy;

webRequest.Method = "GET";

webRequest.Accept = "*/*";

webRequest.UserAgent = userAgent;

webRequest.CookieContainer = cookies;

//Request and get the response

webResponse = webRequest.GetResponse() as HttpWebResponse;

//Update the cookies

cookies.Add(webResponse.Cookies);

response = new StreamReader(webResponse.GetResponseStream());

//code to postdata

webRequest = HttpWebRequest.Create(url) as HttpWebRequest;

webRequest.Proxy = proxy;

webRequest.Method = "POST";

webRequest.Accept = "*/*";

webRequest.UserAgent = userAgent;

webRequest.CookieContainer = cookies;

webRequest.ProtocolVersion = HttpVersion.Version10;

webRequest.ContentType = "application/x-www-form-urlencoded";

webRequest.ContentLength = postData.Length;

using (StreamWriter writer = new StreamWriter(webRequest.GetRequestStream()))

{

writer.Write(postData);

writer.Close();

}

//Request and get the response

webResponse = webRequest.GetResponse() as HttpWebResponse;

//Update the cookies

cookies.Add(webResponse.Cookies);

response = new StreamReader(webResponse.GetResponseStream());

can anybody help on where the mistake is?



thanks

Rama
Apr 4 '07 #1
0 1039

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Mach Runner | last post: by
10 posts views Thread by DavidPr | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.