Click here to Skip to main content
12,953,263 members (81,966 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to login to the password secures website using web request.The following is my code.Am unable to login to the site.Please help me out
Posted 11-Jun-12 20:42pm
Updated 17-Dec-12 21:23pm
Sandeep Mewara 12-Jun-12 3:05am
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try to close the request stream before retrieving the response.
You can accomplish this by using "using" blocks:

public string login(string url, string postData)
    byte[] requestData = Encoding.UTF8.GetBytes(postData);
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.ContentLength = requestData .Length;
    using (Stream requestStream = webRequest.GetRequestStream())
        webpageStream.Write(requestData, 0, requestData.Length);
    } //this will close the requestStream automatically
    WebResponse webpageResponse = webRequest.GetResponse();
    using (responseReader = new StreamReader(webpageResponse.GetResponseStream()))
        return webpageReader.ReadToEnd();
    } //the reader will close the underlaying stream too

(Besides, I've done some style improvements you should adopt, the code will be a far more readable)

For more infos, see a Tutorial on MSDN.[^]


Never do that!
What is Response? (A rhetorical question)
This is called bad side effects...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100