string appURL = "http://blahblah.com";
string strPostData = String.Format("userName={0}&password={1}",
"username", "password");
// Setup the http request.
HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as
HttpWebRequest;
wrWebRequest.Method = "post";
wrWebRequest.ContentLength = strPostData.Length;
wrWebRequest.ContentType = "application/x-www-form-urlencoded";
CookieContainer cookieContainer = new CookieContainer();
wrWebRequest.CookieContainer = cookieContainer;
// Post to the login form.
StreamWriter swRequestWriter = new
StreamWriter(wrWebRequest.GetRequestStream());
swRequestWriter.Write(strPostData);
swRequestWriter.Close();
// Get the response.
HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
// Read the response
StreamReader srResponseReader = new
StreamReader(hwrWebResponse.GetResponseStream());
string strResponseData = srResponseReader.ReadToEnd();
srResponseReader.Close();
Response.Write(strResponseData);
return cookieContainer;
Could anyone please help and send me the code?