Problem with HttpWebRequest to read a web page

  • Thread starter Thread starter etantonio
  • Start date Start date
E

etantonio

Good Morning,
I need to read a web page, to do this I use the following code that
works well if I choose

sAddressTime = "http://www.etantonio.it/it/index.aspx"

and you can see the trace results at
http://www.etantonio.it/it/trad_OK.aspx

while it is not working if I choose

sAddressTime =
"http://babelfish.altavista.com/babe...versita/MasterSatellitare/index.aspx&lp=IT_EN";


and in this case you can see the trace results at
http://www.etantonio.it/it/trad_NOT_OK.aspx

the page I ask for could be regularly seen with a web browser at this
address :
http://babelfish.altavista.com/babe...versita/MasterSatellitare/index.aspx&lp=IT_EN


but when I ask to open it with my script this is the error reported :
System.Net.WebException: The underlying connection was closed: The
server committed an HTTP protocol violation.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at ASP.Trad_NOT_OK_aspx.Page_Load(Object Src, EventArgs E) in
D:\Inetpub\webs\etantonioit\it\trad_NOT_OK.aspx:line 15


here it is the simple code and I hope you can help me to solve the
error:

****************************************************************************
<%@ Page Language="c#" Trace="true" Debug="true" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
void Page_Load(Object Src, EventArgs E )
{
if (!Page.IsPostBack)
{
String sAddressTime =
""http://babelfish.altavista.com/babe...versita/MasterSatellitare/index.aspx&lp=IT_EN";
// String sAddressTime = "http://www.etantonio.it/it/index.aspx";

Trace.Write("sAddressTime",sAddressTime);
try
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(sAddressTime);
HttpWebResponse result = (HttpWebResponse)req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
StreamReader reader = new StreamReader(ReceiveStream,
Encoding.ASCII);
String respHTML = reader.ReadToEnd();
Trace.Write("respHTML",respHTML);
}
catch (Exception e)
{
Trace.Write("EX" , e.ToString());
}
}
}
</script>
<html><head><title>Etantonio</title></head><body ></body></html>
****************************************************************************

many thanks for your help,

Antonio D'Ottavio
www.etantonio.it/en/
 
The error raised from that server is this :

The underlying connection was closed: The server committed an HTTP
protocol violation.
Status: ServerProtocolViolation

how I can bypass it ?? Can you help me ??
Many thanks

Antonio D'Ottavio
www.etantonio.it/en/
 
The error raised from that server is this :

The underlying connection was closed: The server committed an HTTP
protocol violation.
Status: ServerProtocolViolation

how I can bypass it ?? Can you help me ??

..NET 2.0 is bit more specific regarding that error:

System.Net.WebException: The server committed a protocol violation.
Section=ResponseHeader Detail=CR must be followed by LF

That *is* a protocol violation :-/

Cheers,
 
So this is the true error but how I can resolve this ??
The strange is that there is no error if I open with Internet explorer
this page :

http://babelfish.altavista.com/babelfish/trurl_pagecontent?url=http:
%2f%2fwww.etantonio.it%2fIT%2fUniversita%2fMasterSatellitare%2findex.a
spx&lp=IT_EN

Well, IE does use a different HTTP implementation which is more lenient
;-)

while if I read the page with my script at the link :

http://www.etantonio.it/it/trad_NOT_OK.aspx

I have the protocol violation. There is a way to not consider this
protocol violation ??

I'm afraid not -- unless you roll your own HTTP stack or use P/Invoke
to call WinHTTP.

One thing to consider: This problem may also cause any infrastructure
component in between to fail...

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top