Hello i sending postRequest and postPesponse in 1 step all good in 2 step the cookies is empty....What i am missing here?
CookieCollection cookies = new CookieCollection();
CookieCollection cookiesAfterLogin = new CookieCollection();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginGetUrl);
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
//Get the response from the server and save the cookies from the first request..
1step HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies;
Stream streamResponseLogin = response.GetResponseStream();
StreamReader streamReadLogin = new StreamReader(streamResponseLogin);
LoginInfo = streamReadLogin.ReadToEnd();
string postData = null;
postData += "__EVENTARGUMENT=" + GetValueByID(LoginInfo, "__EVENTARGUMENT") + "&";//The new
postData += "__REQUESTDIGEST=" + GetValueByID(LoginInfo, "__REQUESTDIGEST") + "&";
postData += "__VIEWSTATE=" + GetValueByID(LoginInfo, "__VIEWSTATE") + "&";
postData += "__EVENTVALIDATION=" + GetValueByID(LoginInfo, "__EVENTVALIDATION") + "&";
postData += "homeLogin$txtUsername=xx&";
postData += "homeLogin$txtPassword=xxx&";
postData += "__EVENTTARGET=homeLogin$connectLb";
HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(loginPostUrl);
postRequest.CookieContainer = new CookieContainer();
// Add the received Cookies from the HTTP Get
postRequest.CookieContainer.Add(cookies);
postRequest.Method = WebRequestMethods.Http.Post;
postRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
postRequest.AllowWriteStreamBuffering = false;
postRequest.ProtocolVersion = HttpVersion.Version11;
postRequest.AllowAutoRedirect = false;
postRequest.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
postRequest.ContentLength = byteArray.Length;
Stream newStream = postRequest.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
2step HttpWebResponse postResponseAfterLogin = (HttpWebResponse)postRequest.GetResponse();
cookiesAfterLogin = postResponseAfterLogin.Cookies;
//ANd here --->cookiesAfterLogin.Count is 0
Sow here is the promleb after this i doing the new redirect to page but as you see cookies is empty and i get stack.Any ideas?
I just find out that in postResponseAfterLogin i have this function in side of code with my link that i need and timeOut(2000).This can help to resolve this problem?
<script type="text/javascript">
//<![CDATA[
getLoader_Side(); function loginRedirect() { setTimeout("UpdateLoaderImg()", 50); top.location.href ="https://services.test.com/Pages/Trans.aspx";} setTimeout("loginRedirect()", 2000); var _spFormDigestRefreshInterval = 1440000;Sys.Application.initialize();
//]]>
Use for the second request
postRequest.CookieContainer = request.CookieContainer;
This will use the cookies of the first request.
Otherwise, you must set the right URI when you add the cookies manually
http://msdn.microsoft.com/en-us/library/ckch3yd2(v=vs.110).aspx
You can try the cookie aware web client like the below one:
https://gist.github.com/paigecook/5221158
Try using Static Methods:
For save:
HttpContext.Current.Response.Cookies.Add["MyField"];
HttpContext.Current.Request.Cookies["MyField"];
Related
I created an windows form application that goes to a website and does a HTTPwebrequest POST and then displays the result in a webbrowser. I tested it on the computer that I wrote the program on and it works exactly like it should. However when I get the .exe file from the bin folder along with htmlagilitypack.dll and run a test on another computer, it does the POST data but web page that shows up in broswer is just the default login page. I have looked at it on fiddler and it seems like the cookies aren't getting set to the webbrowser. How can I fix this? I have also compiled the program in release mode and transferred the files in the release folder and its the same result.
On the program I used this to set the cookie for the browser.
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetSetCookie(string lpszUrlName, string lpszCookieName, string lpszCookieData);
Does it have to do something with that dll file?
Edit: I have made sure both computer has 4.5 NET installed.
//get the cookie first
CookieCollection cookies = new CookieCollection();
CookieContainer cookiecontainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.supremenewyork.com" + url);
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
//get the auth token
using (StreamReader authreader = new StreamReader(request.GetResponse().GetResponseStream()))
{
source = authreader.ReadToEnd();
}
//need the auth token
string token = Regex.Match(source, "authenticity_token.+?value=\"(.+?)\"").Groups[1].Value;
//need the POST url
string action = Regex.Match(source, "UTF-8.+?action=\"(.+?)\"").Groups[1].Value;
//get the reponse from the server and save the cookies from the first request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies;
response.Close();
string formparam = string.Format("utf8=%E2%9C%93&authenticity_token={0}&size={1}&commit=add to cart", token, sizechart[0]);
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create("http://www.supremenewyork.com"+ action);
webreq.CookieContainer = new CookieContainer();
webreq.CookieContainer = request.CookieContainer;
//webreq.CookieContainer.Add(cookies); //recover the cookie first request
webreq.Method = "POST"; //set a POST method
webreq.Referer = "http://www.supremenewyork.com" + url;
webreq.ContentType = "application/x-www-form-urlencoded";
webreq.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36";
webreq.KeepAlive = true;
webreq.AllowAutoRedirect = true;
byte[] bytes = Encoding.UTF8.GetBytes(formparam);
webreq.ContentLength = bytes.Length;
//write
Stream postdata = webreq.GetRequestStream(); //open connection
postdata.Write(bytes, 0, bytes.Length); //send the data
postdata.Close();
//get the final response from the server
HttpWebResponse resp = (HttpWebResponse)webreq.GetResponse();
cookies = resp.Cookies;
response.Close();
//Stream answer = resp.GetResponseStream();
//StreamReader _answer = new StreamReader(webreq.GetResponse().GetResponseStream());
//string reply = _answer.ReadToEnd();
//need to check if item has been added to cart
//richTextBox1.Text = reply;
//check if item has been added to cart
HttpWebRequest webreq2 = (HttpWebRequest)WebRequest.Create("http://www.supremenewyork.com/shop/cart");
//webreq2.CookieContainer = new CookieContainer();
webreq2.CookieContainer = webreq.CookieContainer;
HttpWebResponse resp2 = (HttpWebResponse)webreq2.GetResponse();
Stream answer2 = resp2.GetResponseStream();
StreamReader _answer2 = new StreamReader(webreq2.GetResponse().GetResponseStream());
string reply2 = _answer2.ReadToEnd();
string item = textBoxkeyword.Text;
string color = textBoxcolor.Text.ToLower();
if(reply2.Contains(color))
{
//proceed to check out
//update user
appendtext(nDateTime + item + " " + color + " added to cart" );
appendtext(nDateTime + "Please check out the item");
HttpWebRequest webreq3 = (HttpWebRequest)WebRequest.Create("http://www.supremenewyork.com/checkout");
//webreq3.CookieContainer = new CookieContainer();
webreq3.CookieContainer = webreq2.CookieContainer;
HttpWebResponse resp3 = (HttpWebResponse)webreq3.GetResponse();
//webBrowser1.ScriptErrorsSuppressed = false;
//RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Internet Explorer\Main", true);
//RegKey.SetValue("Display Inline Images", "yes");
string cookie_string = "";
foreach (Cookie cook in resp3.Cookies)
{
cookie_string += cook.ToString() + ";";
InternetSetCookie("http://www.supremenewyork.com/checkout", cook.Name, cook.Value);
}
webBrowser1.Navigate("http://www.supremenewyork.com/checkout");
}
Edit2: added all the code
I'm trying to log in to website. Following settings works when i use putty:
GET /WindchillCProdA/netmarkets/jsp/netmarkets/view.jsp HTTP/1.1
Host: www.host_address.com
Cookie: action_number=0
Authorization: Basic bG9naW46cGFzc3dvcmQ=
I've used following code to make the same thing in C#:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.webpage.com/WindchillCProdA/netmarkets/jsp/netmarkets/view.jsp");
request.Method = "GET";
CookieContainer gaCookies = new CookieContainer();
gaCookies.Add(new Cookie("action_number", "0") { Domain = request.Host });
request.Host = www.host_address.com;
request.CookieContainer = gaCookies;
request.UserAgent = "HTTP/1.1";
request.Headers["Authorization"] = "Basic " + "bG9naW46cGFzc3dvcmQ=";
I'm receiving:
The remote server returned an error: (401) Unauthorized.
I suspect that i have to fill somehow view.jsp because my parameters are not used in this case.
use post method and write on request stream the values,
i Checked the web site and i was redirected to another page the code should be as bellow
//there could be some hash check the scripts via inspect Element
string postData = String.Format("email={0}&newPassword={1}", "yourusername","yourPassword");
var request = (HttpWebRequest)WebRequest.Create("https://secure.systemsecure.com/host/login/23.htm");
getRequest.Method = WebRequestMethods.Http.Post;
getRequest.CookieContainer = new CookieContainer();
getRequest.UserAgent ="Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko)Chrome/15.0.874.121 Safari/535.2";
getRequest.AllowWriteStreamBuffering = true;
getRequest.ProtocolVersion = HttpVersion.Version10;
getRequest.AllowAutoRedirect = true;
getRequest.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
getRequest.ContentLength = byteArray.Length;
Stream newStream = getRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
var getResponse = (HttpWebResponse)getRequest.GetResponse();
I'm trying to login on facebook and retrive a token by using this link:
https://www.facebook.com/dialog/oauth?client_id=282892925078054&redirect_uri=https://www.facebook.com/&response_type=token
My code looks like this, but i get an invalid link when i'm requesting the link above.
CookieCollection cookies = new CookieCollection();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.facebook.com/login.php?login_attempt=1");
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
//Get the response from the server and save the cookies from the first request..
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies;
string getUrl = "https://www.facebook.com/login.php?login_attempt=1";
string postData = String.Format("email={0}&pass={1}", email, pass);
HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
getRequest.CookieContainer = new CookieContainer();
getRequest.CookieContainer.Add(cookies); //recover cookies First request
getRequest.Method = WebRequestMethods.Http.Post;
getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
getRequest.AllowWriteStreamBuffering = true;
getRequest.ProtocolVersion = HttpVersion.Version11;
getRequest.AllowAutoRedirect = true;
getRequest.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
getRequest.ContentLength = byteArray.Length;
Stream newStream = getRequest.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
cookies = getResponse.Cookies;
using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
{
string sourceCode = sr.ReadToEnd();
}
//Get the token
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://www.facebook.com/dialog/oauth?client_id=282892925078054&redirect_uri=https://www.facebook.com/&response_type=token");
getRequest.CookieContainer = new CookieContainer();
getRequest.CookieContainer.Add(cookies);
webRequest.AllowAutoRedirect = false;
HttpWebResponse rresponse = (HttpWebResponse)webRequest.GetResponse();
if (rresponse.StatusCode == HttpStatusCode.Redirect)
{
Console.WriteLine("redirected to: " + rresponse.GetResponseHeader("Location"));
}
Please help me. Thanks in advance.
https://www.facebook.com/dialog/oauth?client_id=282892925078054&redirect_uri=https://www.facebook.com/&response_type=token
The URL does not allow the application configuration.: The application settings do not allow one or more of the URLs. Internet Site URL and Canvas URL or domain URLs must be sub-domains of application domains.
I have task of uploading file to java servlet. I installed Fiddler to see where web requests are sent and what post data is sent. After logging into java servlet using HttpWebRequest GET method I receive in cookies SessionId. So I was using this SessionId in headers to create POST request to the web server where servlet is. But in response I receive message that "session is time out. Try to login again." But if I use application through user interface I have the one SessionId for all application which is sent in headers with each request.
This application is running in bank so I was thinking if they have some security against scraping.
Am I thinking in a right way? Any help will be appreciated.
Thanks, Elena
Here is my code
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://go.tkygw.pcnet.smbc.local/MgbTokyoGateway/Mgblinkmenu.aspx");
req.Credentials = new NetworkCredential("GB54326", "elena83", "TKYGW");
req.CookieContainer = cookieContainer;
req.Headers.Add("Pragma", "no-cache");
req.Headers.Add("Accept-Language", "en-gb");
req.ProtocolVersion = HttpVersion.Version10;
req.AllowAutoRedirect = true;
WebResponse resp = req.GetResponse();
//here in cookies I receive ASP.NET_session_Id and tkygw_intra
HttpWebResponse webr = (HttpWebResponse)resp;
StreamReader r = new StreamReader(resp.GetResponseStream(), System.Text.Encoding.UTF8);
string res = r.ReadToEnd();
resp.Close();
NameValueCollection nvc = new NameValueCollection();
nvc.Add("_PAGEID", "MWMAL1000P00");
nvc.Add("_SENDTS", "1296208904759");
nvc.Add("_TRANID", "AL1000T00P01");
nvc.Add("_SUBINDEX", "-1");
nvc.Add("_TARGET", "");
nvc.Add("_FRAMID", "");
nvc.Add("_LUID", "1296208904720");
nvc.Add("_WINID", "root");
nvc.Add("_TARGETWINID", "TIMEOUTW_300000_13");
nvc.Add("CHK_FLG", "0");
nvc.Add("BUTTON_NAME", "Corporate Card");
nvc.Add("TITLE_NAME", "[AL1000]Main Menu");
nvc.Add("DateFormat", "1");
nvc.Add("BIZKEY", "AC");
nvc.Add("H_REG_NUM", "");
nvc.Add("H_TODO_DISP_MODE", "");
nvc.Add("H_VIEW_CHANGE_FLG", "1");
nvc.Add("H_SMVA_FLG", "0");
nvc.Add("H_SWITCH_ID", "8837");
nvc.Add("T_BOOKING", "8802");
nvc.Add("T_CUSTOMER_ID", "109732");
nvc.Add("P_DATE_FM", "1");
nvc.Add("D_BA_CREDIT_MONITORING_DISABLED", "");
nvc.Add("D_BA_CREDIT_APPLICATION_DISABLED", "");
nvc.Add("D_BA_CREDIT_APPLICATION_DISABLED", "");
nvc.Add("P_BLANKET_APPLI", "");
HttpWebRequest req3 = (HttpWebRequest)WebRequest.Create("http://gcm.tkygw.pcnet.smbc.local/gcmv0/WACSServlet");
//here in cookiesContainer are 4 values: ASP.NET_session_Id , tkygw_intra
req3.CookieContainer = cookieContainer;
req3.Method = "POST";
req3.Accept = "*/*";
// req3.Headers.Add("Pragma", "no-cache");
// req3.Headers.Add("Accept-Language", "en-gb");
req3.AllowAutoRedirect = true;
req3.KeepAlive = true;
req3.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
req3.ContentType = "application/x-www-form-urlencoded";
req3.ProtocolVersion = HttpVersion.Version10;
var sbPostData = new StringBuilder();
if (nvc != null)
{
foreach (string key in nvc.AllKeys)
{
string[] values = nvc.GetValues(key);
if (values != null)
{
foreach (string value in values)
{
if (!string.IsNullOrEmpty(value))
sbPostData.Append(string.Format("{0}={1}&", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(value)));
}
}
}
}
var parameterString = Encoding.UTF8.GetBytes(sbPostData.ToString());
req3.Referer = "http://gcm.tkygw.pcnet.smbc.local/gcmv0/WACSServlet?_TRANID=AL0010P01C01";
req3.ContentLength = sbPostData.ToString().Length;
using (Stream requestStream = req3.GetRequestStream())
{
requestStream.Write(parameterString, 0, parameterString.Length);
requestStream.Close();
//nothig is received in cookies. Status of response 200 (OK), but on the web page is error that Session is Time OUT. Please Login again
using (var response = req3.GetResponse() as HttpWebResponse)
{
using (var stIn = new System.IO.StreamReader(response.GetResponseStream()))
{
//here I receive session Time Out. Please login again
string s = stIn.ReadToEnd();
}
}
}
If you are uploading file using HttpWebRequest, you must specify content headers correct.
Content must be specified as Content-Type: multipart/form-data
sample snippet
string DataBoundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x");
string contentType = "multipart/form-data; boundary=" + DataBoundary ;
req.Method = "POST";
req.ContentType = contentType ;
req.UserAgent = userAgent;
req.CookieContainer = new CookieContainer();
req.ContentLength = formData.Length;
Check out this and this posts for more detail explanation
Okay I tried asking this question yesterday but i'm not sure if I gave enough info, i got an answer but it hasn't worked for me. Basically what i'm doing is the user opens this windows forms application and logs in. Afterwhich they enter some text into a textbox and click run. At this point the run function is making a webrequest to a server that requires a login (the login that is initially done after they open the program. For some reason its still not seeing that the user is logged in when performing the second request even though the cookies are added too a cookie container. I'm not sure what i'm doing wrong but I will post my code so you can further help me.
This is the function that is performed for the login when the user enters the application.
private void button1_Click(object sender, EventArgs e)
{
string paramaters = "authmethod=on&chkRememberMe=on&login-form-type=pwd&password=" + pw.Text + "&userid=" + uid.Text + "&username=" + uid.Text;
string strResponse;
HttpWebRequest requestLogin = (HttpWebRequest)WebRequest.Create("https://www.url.com/login.form");
requestLogin.Method = "POST";
requestLogin.CookieContainer = cookieJar;
requestLogin.ContentType = "application/x-www-form-urlencoded";
requestLogin.ContentLength = paramaters.Length;
StreamWriter stOut = new StreamWriter(requestLogin.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(paramaters);
stOut.Close();
HttpWebResponse responseLogin = (HttpWebResponse)requestLogin.GetResponse();
StreamReader stIn = new StreamReader(responseLogin.GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
//Add cookies to CookieJar (Cookie Container)
foreach (Cookie cookie in responseLogin.Cookies)
{
cookieJar.Add(new Cookie(cookie.Name.Trim(), cookie.Value.Trim(), cookie.Path, cookie.Domain));
richTextBox2.Text += cookie.Name.ToString() + Environment.NewLine + cookie.Value.ToString() + Environment.NewLine + cookie.Path.ToString() + Environment.NewLine + cookie.Domain.ToString();
}
if (strResponse.Contains("Log On Successful") || strResponse.Contains("already has a webseal session"))
{
foreach (Control cont in this.Controls)
{
cont.Visible = true;
}
loginPanel.SendToBack();
loginPanel.Visible = false;
}
else
{
MessageBox.Show("Login failed.");
}
}
This is the function that is ran when the user clicks the "run" button to initiate the tests on a consumer account.
private string runTestRequest(Uri url, string parameters)
{
string testResults = string.Empty;
HttpWebRequest runTest = (HttpWebRequest)WebRequest.Create(url);
runTest.CookieContainer = cookieJar;
runTest.Method = "POST";
runTest.ContentType = "application/x-www-form-urlencoded";
StreamWriter stOut = new StreamWriter(runTest.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(parameters);
stOut.Close();
StreamReader stIn = new StreamReader(runTest.GetResponse().GetResponseStream());
testResults = stIn.ReadToEnd();
stIn.Close();
return testResults;
}
And of course this is my cookie container object
public CookieContainer cookieJar = new CookieContainer();
P.S.: The domains of the webrequests are different. First being abc.com 2nd being 123.com The only problem is that the first domain (which is the login) is a global login for internal web applications like 123.com, so how would i use the login session from the 1st domain with the 2nd domain?
Can you please assist in helping me figure out what I am doing wrong.
I found out that what was happening was it was redircting to a subdomain on the same domain as the 2nd (123.com) to use the login. Evidently they had this global login system built on the multiple domains to pass the cookies. The code above DOES work and i do have it working now. Thanks!!
string url = "http://www.ABC/MemberShip/Login.aspx";// HttpContext.Current.Request.Url.AbsoluteUri.ToString().Replace("AutoLogin", "Login");
CookieContainer myCookieContainer = new CookieContainer();
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.CookieContainer = myCookieContainer;
request.Method = "GET";
request.KeepAlive = false;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
string srcString = reader.ReadToEnd();
// get the page ViewState
string viewStateFlag = "id=\"__VIEWSTATE\" value=\"";
int i = srcString.IndexOf(viewStateFlag) + viewStateFlag.Length;
int j = srcString.IndexOf("\"", i);
string viewState = srcString.Substring(i, j - i);
// get page EventValidation
string eventValidationFlag = "id=\"__EVENTVALIDATION\" value=\"";
i = srcString.IndexOf(eventValidationFlag) + eventValidationFlag.Length;
j = srcString.IndexOf("\"", i);
string eventValidation = srcString.Substring(i, j - i);
string submitButton = "LoginButton";
// UserName and Password
string userName = "userid";
string password = "password";
// Convert the text into the url encoding string
viewState = System.Web.HttpUtility.UrlEncode(viewState);
eventValidation = System.Web.HttpUtility.UrlEncode(eventValidation);
submitButton = System.Web.HttpUtility.UrlEncode(submitButton);
// Concat the string data which will be submit
string formatString =
"txtUserName={0}&txtPassword={1}&btnSignIn={2}&__VIEWSTATE={3}&__EVENTVALIDATION={4}";
string postString =
string.Format(formatString, userName, password, submitButton, viewState, eventValidation);
// Convert the submit string data into the byte array
byte[] postData = Encoding.ASCII.GetBytes(postString);
// Set the request parameters
request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.Referer = url;
request.KeepAlive = false;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; CIBA)";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = myCookieContainer;
System.Net.Cookie ck = new System.Net.Cookie("TestCookie1", "Value of test cookie");
ck.Domain = request.RequestUri.Host;
request.CookieContainer.Add(ck);
request.CookieContainer.Add(response.Cookies);
request.ContentLength = postData.Length;
// Submit the request data
System.IO.Stream outputStream = request.GetRequestStream();
request.AllowAutoRedirect = true;
outputStream.Write(postData, 0, postData.Length);
outputStream.Close();
// Get the return data
response = request.GetResponse() as HttpWebResponse;
responseStream = response.GetResponseStream();
reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
srcString = reader.ReadToEnd();
Response.Write(srcString);
Response.End();