How to Remove Http header from http response

Discussion in 'XML' started by Vivek Mehta, Aug 11, 2004.

  1. Vivek Mehta

    Vivek Mehta Guest

    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.
    Vivek Mehta, Aug 11, 2004
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Aug 11, 2004
    #2
    1. Advertising

  3. (Vivek Mehta) writes in article <> 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.
    Keith A. Lewis, Aug 11, 2004
    #3
  4. Vivek Mehta

    Vivek Mehta Guest

    Martin Honnen <> wrote in message news:<411a0e4c$>...
    > 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.
    Vivek Mehta, Aug 12, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alfons Puig

    Alternate to HTTP Response Header Refresh

    Alfons Puig, Aug 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    599
    Charlie Nilsson [MSFT]
    Aug 30, 2003
  2. Joona I Palaste

    Java Servlets: Remove a HTTP header?

    Joona I Palaste, Nov 4, 2003, in forum: Java
    Replies:
    5
    Views:
    15,192
  3. mike
    Replies:
    2
    Views:
    912
  4. mlt
    Replies:
    2
    Views:
    817
    Jean-Marc Bourguet
    Jan 31, 2009
  5. Katie
    Replies:
    8
    Views:
    254
    Anthony Jones
    Aug 17, 2006
Loading...

Share This Page