473,394 Members | 1,674 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,394 software developers and data experts.

WebResponse Class Problems

I'm having odd problems with the WebResponse class. Some servers are
speedy, while others don't play along at all. Consider the following pages*:

http://planetbrent.com/test.aspx?url.../www.yahoo.com
http://planetbrent.com/test.aspx?url=http://www.msn.com
http://planetbrent.com/test.aspx?url=http://www.sec.gov
http://planetbrent.com/test.aspx?url...-05-001703.txt

The first two return HTML all-but instantly. The third and fourth links
-- both on the same server, I'm guessing -- take up to a minute, which
you can see if you test them. The four pages are roughly the same size
in bytes.

I'm thinking there may be an issue with the way the response comes back
from the server. Is it possible that some servers deliver data that's
confusing to the Http/WebResponse class? Or could the problem relate to
the headers I'm sending in my request.

I'd sure appreciate any pointers on handling this situation!

--Brent

*Full source code for the page.
================================================== =======
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Data" %>

<script language="C#" runat="server">

public void Page_Load(Object sender, EventArgs e)
{
string url = Request.QueryString["url"] != null ?
Request.QueryString["url"] : "http://www.yahoo.com";
ctrlSF.Text = "Started: " +
System.DateTime.Now.ToString("HH:mm:ss") + " | ";
ctrlText.Text = getHeader(url);
ctrlSF.Text += "Finished: " + System.DateTime.Now.ToString("HH:mm:ss");
}
public string getHeader (string strURL)
{
StringBuilder returnString = new StringBuilder();

String strreturn;
String thisRow = "";

WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();

using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
while ((thisRow = sr.ReadLine()) != null)
{
returnString.Append(thisRow);
}
}
return returnString.ToString();
}

</script>

<asp:Literal id="ctrlSF" runat="server" />
<asp:Literal id="ctrlText" runat = "server" />
Nov 17 '05 #1
6 1624
You also have an internal limit of 2 requests per connection that may be
clogging up the lines. You can test this difference by switching the order
of the requests. Slow times for the originally fast sites would indicate a
problem related to the request/response and not the site. See if that helps
any.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:11*************@corp.supernews.com...
I'm having odd problems with the WebResponse class. Some servers are
speedy, while others don't play along at all. Consider the following pages*:
http://planetbrent.com/test.aspx?url.../www.yahoo.com
http://planetbrent.com/test.aspx?url=http://www.msn.com
http://planetbrent.com/test.aspx?url=http://www.sec.gov
http://planetbrent.com/test.aspx?url...-05-001703.txt
The first two return HTML all-but instantly. The third and fourth links
-- both on the same server, I'm guessing -- take up to a minute, which
you can see if you test them. The four pages are roughly the same size
in bytes.

I'm thinking there may be an issue with the way the response comes back
from the server. Is it possible that some servers deliver data that's
confusing to the Http/WebResponse class? Or could the problem relate to
the headers I'm sending in my request.

I'd sure appreciate any pointers on handling this situation!

--Brent

*Full source code for the page.
================================================== =======
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Data" %>

<script language="C#" runat="server">

public void Page_Load(Object sender, EventArgs e)
{
string url = Request.QueryString["url"] != null ?
Request.QueryString["url"] : "http://www.yahoo.com";
ctrlSF.Text = "Started: " +
System.DateTime.Now.ToString("HH:mm:ss") + " | ";
ctrlText.Text = getHeader(url);
ctrlSF.Text += "Finished: " + System.DateTime.Now.ToString("HH:mm:ss"); }
public string getHeader (string strURL)
{
StringBuilder returnString = new StringBuilder();

String strreturn;
String thisRow = "";

WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();

using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
while ((thisRow = sr.ReadLine()) != null)
{
returnString.Append(thisRow);
}
}
return returnString.ToString();
}

</script>

<asp:Literal id="ctrlSF" runat="server" />
<asp:Literal id="ctrlText" runat = "server" />

Nov 17 '05 #2
It could easily be as simple as the first two links are cached or the web
servers are slow/traffic is high, therefore delivered very quickly or very
slowly as a response from the web server.

You need to do some testing first to determine if the pages respond as fast
or as slow as each other without the .net classes in the loop - and build
your findings out of that.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:11*************@corp.supernews.com...
I'm having odd problems with the WebResponse class. Some servers are
speedy, while others don't play along at all. Consider the following
pages*:

http://planetbrent.com/test.aspx?url.../www.yahoo.com
http://planetbrent.com/test.aspx?url=http://www.msn.com
http://planetbrent.com/test.aspx?url=http://www.sec.gov
http://planetbrent.com/test.aspx?url...-05-001703.txt

The first two return HTML all-but instantly. The third and fourth links --
both on the same server, I'm guessing -- take up to a minute, which you
can see if you test them. The four pages are roughly the same size in
bytes.

I'm thinking there may be an issue with the way the response comes back
from the server. Is it possible that some servers deliver data that's
confusing to the Http/WebResponse class? Or could the problem relate to
the headers I'm sending in my request.

I'd sure appreciate any pointers on handling this situation!

--Brent

*Full source code for the page.
================================================== =======
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Data" %>

<script language="C#" runat="server">

public void Page_Load(Object sender, EventArgs e)
{
string url = Request.QueryString["url"] != null ?
Request.QueryString["url"] : "http://www.yahoo.com";
ctrlSF.Text = "Started: " + System.DateTime.Now.ToString("HH:mm:ss") +
" | ";
ctrlText.Text = getHeader(url);
ctrlSF.Text += "Finished: " +
System.DateTime.Now.ToString("HH:mm:ss");
}
public string getHeader (string strURL)
{
StringBuilder returnString = new StringBuilder();

String strreturn;
String thisRow = "";

WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();

using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
while ((thisRow = sr.ReadLine()) != null)
{
returnString.Append(thisRow);
}
}
return returnString.ToString();
}

</script>

<asp:Literal id="ctrlSF" runat="server" />
<asp:Literal id="ctrlText" runat = "server" />

Nov 17 '05 #3
Thanks for your responses!

Alvin: I know about the 2 requests per connection issue. Actually, I'm
not requesting anything sequentially here, I'm requesting one site and
then seeing how long it takes to come back. I then close the
WebResponse, reopen it, and then request the next site. I'm not sure how
the connection requests would be affecting the speed.

John: I'm curious how the first two links could be cached, while the
others are not. I've accessed all pages in various ways, both with the
code and directly from a browser on the same machine, and it's only the
code that slows down on http://www.sec.gov. How would I test the
external pages "without the .net classes in the loop" other than looking
at them in a browser?

--Brent
Nov 17 '05 #4
I mean they could be getting delivered via a cache server at the delivery
end, and hence are being delivered somewhat faster. If they appear slow
only in .net and not in your browser this is not likely to be the case.

Have you tried only requesting the second two via your code, or trying an
online analyzer?

http://www.websiteoptimization.com/services/analyze/

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:11*************@corp.supernews.com...
Thanks for your responses!

Alvin: I know about the 2 requests per connection issue. Actually, I'm not
requesting anything sequentially here, I'm requesting one site and then
seeing how long it takes to come back. I then close the WebResponse,
reopen it, and then request the next site. I'm not sure how the connection
requests would be affecting the speed.

John: I'm curious how the first two links could be cached, while the
others are not. I've accessed all pages in various ways, both with the
code and directly from a browser on the same machine, and it's only the
code that slows down on http://www.sec.gov. How would I test the external
pages "without the .net classes in the loop" other than looking at them in
a browser?

--Brent

Nov 17 '05 #5
Hmmm...well, I think I've tried every thing I can think of to make this
code work quickly. The odd thing is that two weeks ago (or so), it
worked just fine. I keep thinking, perhaps, that the server is doing
some tarpitting. Is it possible that an Apache server could slow down a
"non-browser" request? Could I mimic a browser in code? Are there any
possible conflicts in the way the data gets returned or interpreted by
my server -- such that my server gets confused and slows down? Why is
the site just fine when viewed through MSIE on my server, but not
through the code? Why are all the other sites speedy, with ONLY (it
seems) http://www.sec.gov being slow?

It's really frustrating!

Thanks for your replies!

--Brent
John Timney ( MVP ) wrote:
I mean they could be getting delivered via a cache server at the delivery
end, and hence are being delivered somewhat faster. If they appear slow
only in .net and not in your browser this is not likely to be the case.

Have you tried only requesting the second two via your code, or trying an
online analyzer?

http://www.websiteoptimization.com/services/analyze/

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director


Nov 17 '05 #6
br*********@gmail.com wrote:
Hmmm...well, I think I've tried every thing I can think of to make
this code work quickly. The odd thing is that two weeks ago (or so),
it worked just fine. I keep thinking, perhaps, that the server is
doing some tarpitting. Is it possible that an Apache server could
slow down a "non-browser" request? Could I mimic a browser in code?


Yes -- simply set the UserAgent property to whatever your preferred
browser would send.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #7

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

Similar topics

0
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the...
2
by: gizmo | last post by:
Hi, I'm using the following code to request the html source from the quoted site. ...... string url = "http://www1.soccerstand.com/"; WebRequest webRequest = WebRequest.Create(url);...
6
by: RS | last post by:
I have written a utility which currently downloads xml data from a high number (40+) of web based sources in a synchronous manner. When attempting to spawn threads off to speed things up I run...
2
by: trialproduct2004 | last post by:
Hi all. i am having problem at a time of validatiang url. I am using webrequest and webresponse class to get content of particular url. My problem is after using webrequest and webresponse class...
2
by: Jeff G. | last post by:
Hello everyone, I have read through the newsgroups (thank God for 'em!) extensively looking for an example of how to pass a file (PDF) from a webresponse stream down to a web client. Here's the...
0
by: Tony Archer | last post by:
Here's my problem... When I use this code to hit the site in question I'm redirected to another SSL login page. If processed successfully the page creates a cookie and then redirects you to the...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
4
by: CindyH | last post by:
Hi I'm trying to use webrequest - webresponse to post a stream. I have set up a simple test with one aspx form holding the post code and trying to get another aspx form to receive the post on...
4
by: CindyH | last post by:
Hi - hope someone can help with this - this code was working for a while in the 'real' code and then suddenly stopped - not sure what happen. I made two simple forms on localhost to try to test...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.