469,356 Members | 1,893 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

How to Remove Http header from http response

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.
Jul 20 '05 #1
3 9187


Vivek Mehta wrote:
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.


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
me*****@hotmail.com (Vivek Mehta) writes in article <14**************************@posting.google.com > dated 10 Aug 2004 20:55:18 -0700:
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.
Jul 20 '05 #3
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41********@olaf.komtel.net>...
Vivek Mehta wrote:
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.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by jacob c. | last post: by
8 posts views Thread by turnit \(removethis\) | last post: by
5 posts views Thread by Shelly | last post: by
7 posts views Thread by Robert Adkison | last post: by
3 posts views Thread by Christian Lutz | last post: by
1 post views Thread by Nuno Magalhaes | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.