How to Remove Http header from http response

V

Vivek Mehta

I want to receive XML stream generated at another URL however when I
try to load the XML it errors out with one error or the other. I
beleive this XML comes back with HTTP header which actually comes back
as part of the response and obviously causes the
xmlDoc.Load(myResponseStream) to break because the test preceding the
XML makes the xml invalid.

How can I remove this content from the receiving XML stream ?? Here is
some sample code :

..NET Page receiving response

sub Page_Load(sender as object, e as Eventargs)

  Dim wRequest As System.Net.HttpWebRequest
Dim wResponse As System.Net.HttpWebResponse
Dim StreamHandler As System.IO.StreamReader
Dim xmlDoc As New System.Xml.XmlDocument

Try
Dim URL As String = "http://localhost/aspnet/process.asp"
wRequest = System.Net.WebRequest.Create(URL)
wRequest.Headers.Add("Man", "GET " & URL)
wResponse = CType(wRequest.GetResponse,
System.Net.WebResponse)
If wRequest.HaveResponse Then
if wResponse.StatusCode = Net.HttpStatusCode.OK Then
streamHandler = New
System.IO.StreamReader(wResponse.GetResponseStream())
xmlDoc.LoadXml(StreamHandler.ReadToEnd)
MsgBox("[--------" & xmlDoc.InnerText & "-------]")
End If
End If

'Catch ex As System.Net.WebException
Finally
End Try
end sub
 
I always get error at xmldoc.loadXML

Here is the Process.asp to which the call is being made above to send
XML stream.

<html><head> <title>process</title></head>
<body>
<form id="Form1" method="post" runat="server">
<script LANGUAGE="VBSCRIPT" runat="server" >

Response.Buffer=True
Response.ContentType = "text/xml"

With Response

.Write("<?xml version='1.0' ?>" & chr(13))
.Write("<Record>")
.Write("<Name>")
.Write("<Last> Jones </Last>")
.Write("<First> Kim </First>")
.Write("</Name>")
.Write("</Record>" )
End With
</script>
</form>
</body>
</html>


I would really appreciate any help on this.
 
M

Martin Honnen

Vivek said:
I want to receive XML stream generated at another URL however when I
try to load the XML it errors out with one error or the other. I
beleive this XML comes back with HTTP header which actually comes back
as part of the response and obviously causes the
xmlDoc.Load(myResponseStream) to break because the test preceding the
XML makes the xml invalid.

How can I remove this content from the receiving XML stream ?? Here is
some sample code :

.NET Page receiving response

sub Page_Load(sender as object, e as Eventargs)

Dim wRequest As System.Net.HttpWebRequest
Dim wResponse As System.Net.HttpWebResponse
Dim StreamHandler As System.IO.StreamReader
Dim xmlDoc As New System.Xml.XmlDocument

Try
Dim URL As String = "http://localhost/aspnet/process.asp"
wRequest = System.Net.WebRequest.Create(URL)
wRequest.Headers.Add("Man", "GET " & URL)
wResponse = CType(wRequest.GetResponse,
System.Net.WebResponse)
If wRequest.HaveResponse Then
if wResponse.StatusCode = Net.HttpStatusCode.OK Then
streamHandler = New
System.IO.StreamReader(wResponse.GetResponseStream())
xmlDoc.LoadXml(StreamHandler.ReadToEnd)
MsgBox("[--------" & xmlDoc.InnerText & "-------]")
End If
End If


I don't see any need to use all that code to read in the response and
later call loadXML, you can simply use the Load method and pass the URL
of that ASP page e.g.
xmldoc.Load(URL);
I always get error at xmldoc.loadXML

Here is the Process.asp to which the call is being made above to send
XML stream.

<html><head> <title>process</title></head>
<body>

If you want to output XML then you can't have the HTML in your page,
throw that out.
 
K

Keith A. Lewis

I want to receive XML stream generated at another URL however when I
try to load the XML it errors out with one error or the other. I
beleive this XML comes back with HTTP header which actually comes back
as part of the response and obviously causes the
xmlDoc.Load(myResponseStream) to break because the test preceding the
XML makes the xml invalid.

The convention (sorry I don't know which RFC) for separating header from
content is a blank line. In other words, two newlines or linefeeds in a
row. If you write a short loop to read and discard everything until that,
what follows will be pure content.

--Keith Lewis klewis {at} mitre.org
The above may not (yet) represent the opinions of my employer.
 
V

Vivek Mehta

Martin Honnen said:
Vivek said:
I want to receive XML stream generated at another URL however when I
try to load the XML it errors out with one error or the other. I
beleive this XML comes back with HTTP header which actually comes back
as part of the response and obviously causes the
xmlDoc.Load(myResponseStream) to break because the test preceding the
XML makes the xml invalid.

How can I remove this content from the receiving XML stream ?? Here is
some sample code :

.NET Page receiving response

sub Page_Load(sender as object, e as Eventargs)

Dim wRequest As System.Net.HttpWebRequest
Dim wResponse As System.Net.HttpWebResponse
Dim StreamHandler As System.IO.StreamReader
Dim xmlDoc As New System.Xml.XmlDocument

Try
Dim URL As String = "http://localhost/aspnet/process.asp"
wRequest = System.Net.WebRequest.Create(URL)
wRequest.Headers.Add("Man", "GET " & URL)
wResponse = CType(wRequest.GetResponse,
System.Net.WebResponse)
If wRequest.HaveResponse Then
if wResponse.StatusCode = Net.HttpStatusCode.OK Then
streamHandler = New
System.IO.StreamReader(wResponse.GetResponseStream())
xmlDoc.LoadXml(StreamHandler.ReadToEnd)
MsgBox("[--------" & xmlDoc.InnerText & "-------]")
End If
End If


I don't see any need to use all that code to read in the response and
later call loadXML, you can simply use the Load method and pass the URL
of that ASP page e.g.
xmldoc.Load(URL);
I always get error at xmldoc.loadXML

Here is the Process.asp to which the call is being made above to send
XML stream.

<html><head> <title>process</title></head>
<body>

If you want to output XML then you can't have the HTML in your page,
throw that out.


Thanks Martin. You were right XMLDoc.Load(URL) works however my XML
response will be coming from five different databases and I would like
to wait and reject a stream if I don't get a response within the
timeframe I need. I was thinking of using webRequest.timeout feature
to track the amount of time it is taking to capture xml response. Is
there something that can be done with XMLDoc.LOAd(URL) method ?

I removed HTML from ASP page and and the page is only outputting XML
now and I am able to load it now.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top