473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

HttpWebRequest Session/Timeout Problem

I wrote a generic page to do HttpWebRequest operations based on 3
querystring parameters for the uri, username, and password for basic
authentication pages. The page is designed to help with network
management... You would use the page like this:

http://localhost/webform1.aspx?uri=h...&pass=somepass

Anyway, what seems to happen is that the first 2 or 3 calls to the page with
a given set of parameters works great, but then every request after that
times out until you restart the web app. If I try to call a different page
with the uri parameter, it works fine the first 2 or 3 times, then does that
same thing. It's like the web server only allows you to create 2 or 3
sessions and then denies you any more. Is this what's happening? Is there
a way to send a 'Close my Session' command to the web server after I get the
response?

My code is below:
string user;

string pass;

string uri;

private void Page_Load(object sender, System.EventArgs e)

{

if (Request.QueryString["user"]==null || Request.QueryString["pass"]==null
|| Request.QueryString["uri"]==null)

{

Response.Write("Please provide valid user, pass, and uri parameters in the
URL");

Response.End();

}

user = Request.QueryString["user"];

pass = Request.QueryString["pass"];

uri = Request.QueryString["uri"];

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);

webRequest.Credentials = new System.Net.NetworkCredential(user,pass);

webRequest.Timeout = 10000;

webRequest.AllowAutoRedirect = true;

try

{

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

WebHeaderCollection headers = new WebHeaderCollection();

Response.Write("<B>Headers</B><BR>");

for (int x = 0;x<webResponse.Headers.Count;x++)

{

Response.Write(webResponse.Headers.Keys[x] +": "+
webResponse.Headers[x]+"<BR>");

}

Response.Write("<BR><B>Stauts</B><BR>");

Response.Write("StatusCode: " + webResponse.StatusCode+"<BR>");

Response.Write("StatusDescription: " +
webResponse.StatusDescription+"<BR>");

}

catch (Exception ex)

{

Response.Write("Error Getting Page: " +ex.Message);

}

}
Nov 15 '05 #1
1 14180
Nevermind, all that was needed was this:

webResponse.Close();
"Craig" <so*****@microsoft.com> wrote in message
news:0a*********************@twister.rdc-kc.rr.com...
I wrote a generic page to do HttpWebRequest operations based on 3
querystring parameters for the uri, username, and password for basic
authentication pages. The page is designed to help with network
management... You would use the page like this:

http://localhost/webform1.aspx?uri=h...&pass=somepass
Anyway, what seems to happen is that the first 2 or 3 calls to the page with a given set of parameters works great, but then every request after that
times out until you restart the web app. If I try to call a different page with the uri parameter, it works fine the first 2 or 3 times, then does that same thing. It's like the web server only allows you to create 2 or 3
sessions and then denies you any more. Is this what's happening? Is there a way to send a 'Close my Session' command to the web server after I get the response?

My code is below:
string user;

string pass;

string uri;

private void Page_Load(object sender, System.EventArgs e)

{

if (Request.QueryString["user"]==null || Request.QueryString["pass"]==null
|| Request.QueryString["uri"]==null)

{

Response.Write("Please provide valid user, pass, and uri parameters in the
URL");

Response.End();

}

user = Request.QueryString["user"];

pass = Request.QueryString["pass"];

uri = Request.QueryString["uri"];

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);

webRequest.Credentials = new System.Net.NetworkCredential(user,pass);

webRequest.Timeout = 10000;

webRequest.AllowAutoRedirect = true;

try

{

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

WebHeaderCollection headers = new WebHeaderCollection();

Response.Write("<B>Headers</B><BR>");

for (int x = 0;x<webResponse.Headers.Count;x++)

{

Response.Write(webResponse.Headers.Keys[x] +": "+
webResponse.Headers[x]+"<BR>");

}

Response.Write("<BR><B>Stauts</B><BR>");

Response.Write("StatusCode: " + webResponse.StatusCode+"<BR>");

Response.Write("StatusDescription: " +
webResponse.StatusDescription+"<BR>");

}

catch (Exception ex)

{

Response.Write("Error Getting Page: " +ex.Message);

}

}

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jerry Rhodes | last post by:
When I run the code below, the web server tells me that I need to enable cookies. Can anyone tell me what might be causing that? I'm trying to POST userid and password to their login web page. ...
1
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some...
2
by: Keith Patrick | last post by:
I'm trying to programmatically post data to another page within my ASP.Net app. Not POSTing is not an option (I can't store this data in my session, context, hidden fields, or anything else...I've...
11
by: Keith Patrick | last post by:
Could someone explain to me the relationship between these two classes? I am ripping my hair out trying to divert an HttpRequest to a new location via an HttpWebRequest, but I cannot get my...
3
by: Amil | last post by:
Please don't repond to this if you are guessing or just don't know the answer. I'm trying to login to a backend system running Java/Tomcat. I create a HttpWebRequest with the login data and do...
1
by: davvel | last post by:
It has been 6 days of re-writing the same code in different ways to try and avoid a getResponse Timeout which haunted me for much too long now. I am trying to do a very simple thing which is...
0
by: Susan Van Houen | last post by:
Hi Everybody, I have a problem that is driving me crazy and I am hoping for some help here. I am building an application (vb.net, vs2003) that crawls selected websites. The application works...
0
by: Morgan Cheng | last post by:
In the doc http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.timeout.aspx, it reads, "A Domain Name System (DNS) query may take up to 15 seconds to return or time out. If your...
1
by: ALA | last post by:
Hi, does anybody know if it is possible to pass the SessionID with a web request by using a cookie so that the invoked page in the same domain can access the session objects of the current user?...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.