Hello All,
I am having a very strange problem.
while trying to access http page on the web using HTTPWebRequest Class,
I happen to have some problems at specific machines.
The exception I get is:
************* Exception Text **************
System.Net.WebException: The operation has timed-out.
at System.Net.HttpWebRequest.GetResponse()
at wwHTTP.SimpleHttpWebRequest.cmdGo_Click(Object sender, EventArgs
e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
At most of the machines it works just fine.
By the way: THERE IS NO PROXY SERVER DEFINED.
thank you
yariv
The code is as follows:
private void cmdGo_Click(object sender, System.EventArgs e)
{
// *** Establish request by assigning Url
HttpWebRequest loHttp = (HttpWebRequest)
WebRequest.Create(this.txtUrl.Text.TrimEnd());
// *** Set any header related and operational
properties
loHttp.Timeout = 10000; // 10 secs
loHttp.UserAgent = "Code Sample Web Client";
// *** reuse cookies if available
loHttp.CookieContainer = new CookieContainer();
if (this.oCookies != null &&
this.oCookies.Count > 0)
{
loHttp.CookieContainer.Add(this.oCookies);
}
// *** Return the Response data
HttpWebResponse loWebResponse =
(HttpWebResponse)
loHttp.GetResponse();
// ** If the server returns any cookies
// ** add 'em to our cookies collection
if (loWebResponse.Cookies.Count > 0)
if (this.oCookies == null)
{
this.oCookies =
loWebResponse.Cookies;
}
else
{
// ** If we already have
cookies update the list
foreach (Cookie oRespCookie in
loWebResponse.Cookies)
{
bool bMatch = false;
foreach(Cookie
oReqCookie in this.oCookies)
{
if
(oReqCookie.Name == oRespCookie.Name)
{
oReqCookie.Value = oRespCookie.Name;
bMatch
= true;
break;
//
}
}
if (!bMatch)
this.oCookies.Add(oRespCookie);
}
}
Encoding enc = Encoding.GetEncoding(1252); //
Windows-1252 or iso-
if (loWebResponse.ContentEncoding.Length > 0)
{
enc =
Encoding.GetEncoding(loWebResponse.ContentEncoding );
}
StreamReader loResponseStream =
new
StreamReader(loWebResponse.GetResponseStream(),enc );
this.txtHTML.Text =
loResponseStream.ReadToEnd();
loResponseStream.Close();
loWebResponse.Close();
}
thank you,
yariv