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

HttpWebResponse & Webservers

I'm having odd problems with the HttpWebResponse class. Some servers are
quite speedy, while others don't seem to want to talk to my code.
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 a "screen scrape" quite rapidly -- all-but
instantly. The third and fourth links -- both on the same server, I'm
guessing -- take several seconds (if you test them, please be patient!).
The four pages are roughly the same size in bytes.

Viewing the slow pages in a normal browser from the same machine is
acceptably fast.

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 HttpWebResponse class?

I read something about bad chunking (or something like that) from Apache
servers, and that one possible solution was to get bytes instead of
lines. That might be a solution ... except that I need to read through
URLs like the fourth one line-by-line, as each line gets parsed by
other parts of the code.

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">
string rowsdeclared = "";

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 19 '05 #1
2 1122
you need to run a network trace and determine where the delays are. for
example, win2000 has a tendency to use piggyback acks when it shouldn't and
can cause delays over http.

-- bruce (sqlwork.com)

"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 HttpWebResponse class. Some servers are
quite speedy, while others don't seem to want to talk to my code. 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 a "screen scrape" quite rapidly -- all-but instantly.
The third and fourth links -- both on the same server, I'm guessing --
take several seconds (if you test them, please be patient!). The four
pages are roughly the same size in bytes.

Viewing the slow pages in a normal browser from the same machine is
acceptably fast.

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 HttpWebResponse class?

I read something about bad chunking (or something like that) from Apache
servers, and that one possible solution was to get bytes instead of lines.
That might be a solution ... except that I need to read through URLs like
the fourth one line-by-line, as each line gets parsed by other parts of
the code.

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">
string rowsdeclared = "";

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 19 '05 #2
Thanks, Bruce. I have Ethereal installed, but (frankly!) I don't have a
clue about all the bits of data it presents. There are a lot of
red-flagged lines, which I assume mean problems. Whatever. Funny thing:
two weeks ago this same code worked like a champ. Weird.

Is a network trace different from what Ethereal produces?

--Brent

Bruce Barker wrote:
you need to run a network trace and determine where the delays are. for
example, win2000 has a tendency to use piggyback acks when it shouldn't and
can cause delays over http.

-- bruce (sqlwork.com)

Nov 19 '05 #3

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

Similar topics

2
by: Mark Rae | last post by:
Hi, Can anyone please tell me if it's possible to use HttpWebRequest and HttpWebResponse in a class in a Windows application? I've tried referencing System and System.Web but there's still...
10
by: | last post by:
In .NetCF, upon trying to access the following URL: http://rss.news.yahoo.com/rss/business via the following code: WebRequest webReq = WebRequest.Create(url); WebResponse webResp =...
3
by: Karsten Grombach | last post by:
Hi, I'm trying the following: - Imitate a Logon using a Post with HttpWebRequest on remote Webserver (asp 3.0 page using https) - On success redirect to the page (encapsuled in an iframe)...
0
by: SeanGallavan | last post by:
Our Environment: Two network load balanced (using Microsoft NLB software) webservers with session maintained in a SQL Server database. NLB is configured with no affinity settings and two...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
15
by: Snedker | last post by:
I'm using (HttpWebRequest and HttpWebResponse to check for updates. But how do I determine the size of the file before download? What I have in mind is a status text like "You have downloaded...
0
by: dkoppe | last post by:
I'm using C#.NET WebRequest and HTTPResponse to post data to a server and I'm reading the response into a stream. Does anyone know how to split the returned values like a request.form. Here is the...
0
by: Aryan | last post by:
Hi, I am new to HttpWebRequest and HttpWebResponse object, so please help me out for this problem. I am having application which is in ASP.NET. This ASP.NET application talks with ASP and then...
2
by: Joe | last post by:
The example in the msdn shows how to write an image to the OutputStream and the example for GetResponseStream() shows how to read the stream and write it to the console. Unfortunately there is no...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.