Last post Oct 30, 2017 08:09 AM by Kelmen
Oct 27, 2017 08:52 AM|Kelmen|LINK
GetResponseStream keep timed out.
While debuging, it take a long time for the break point i set in the target page, looks like it is working, but for unknown reason it took long~~~~ time be there, and thus the timed out.
var wc = (HttpWebRequest)WebRequest.Create(url);
wc.CookieContainer = new CookieContainer();
for (var i = 0; i < Request.Cookies.Count; i++)
var ck = Request.Cookies[i];
var ckNew = new Cookie();
var args = new StringBuilder();
var postData = Encoding.Default.GetBytes(args.ToString());
wc.Method = "POST";
//wc.Credentials = CredentialCache.DefaultCredentials;
wc.ContentType = "application/x-www-form-urlencoded";
wc.ContentLength = postData.Length;
using (var stream = wc.GetRequestStream())
stream.Write(postData, 0, postData.Length);
var response = (HttpWebResponse)wc.GetResponse();
var txt = new StreamReader(response.GetResponseStream()).ReadToEnd();
did i miss any important setting in the HttpWebRequest?
I need to use this class because only this allow me to manipulate the cookie
I want the target page treat the request as like from user client, and so can access the already established session data.
detail #2, in case it matter:
the target url is "something.aspx?someKey=1", which is typical get-like access method, but i do *post* more data.
Oct 27, 2017 09:47 AM|mgebhard|LINK
There is no way to help you without an knowing the inner workings of the site you are trying to invoke.. I suggest using a tool like Fiddler to record the interactions with the site. Then compare the Fiddler transactions with your code.
Oct 30, 2017 02:34 AM|Kelmen|LINK
more testing showing that setting the cookie causing the timeout.
hinted session is being locked, and its behavior is identical to me
now i need to find out how to deal with this "locked" session in this scenario
Oct 30, 2017 08:09 AM|Kelmen|LINK
my final workout ver is without whacking the session.
just work out another bunch of codes to simulate user login
var wc = new WebClient();
var args = new System.Collections.Specialized.NameValueCollection();
var rslt = wc.UploadValues(url, args);
rptContent = wc.Encoding.GetString(rslt);
need to remark/remove a default coding by the template at App_Start\RouteConfig:
//settings.AutoRedirectMode = RedirectMode.Permanent;
this initially break my post data at the target page.