How to Remove Http header from http response

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vivek Mehta

    #1

    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(myR esponseStream) 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(sende r as object, e as Eventargs)

      Dim wRequest As System.Net.Http WebRequest
    Dim wResponse As System.Net.Http WebResponse
    Dim StreamHandler As System.IO.Strea mReader
    Dim xmlDoc As New System.Xml.XmlD ocument

    Try
    Dim URL As String = "http://localhost/aspnet/process.asp"
    wRequest = System.Net.WebR equest.Create(U RL)
    wRequest.Header s.Add("Man", "GET " & URL)
    wResponse = CType(wRequest. GetResponse,
    System.Net.WebR esponse)
    If wRequest.HaveRe sponse Then
    if wResponse.Statu sCode = Net.HttpStatusC ode.OK Then
    streamHandler = New
    System.IO.Strea mReader(wRespon se.GetResponseS tream())
    xmlDoc.LoadXml( StreamHandler.R eadToEnd)
    MsgBox("[--------" & xmlDoc.InnerTex t & "-------]")
    End If
    End If

    'Catch ex As System.Net.WebE xception
    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>proces s</title></head>
    <body>
    <form id="Form1" method="post" runat="server">
    <script LANGUAGE="VBSCR IPT" runat="server" >

    Response.Buffer =True
    Response.Conten tType = "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.
  • Martin Honnen

    #2
    Re: How to Remove Http header from http response



    Vivek Mehta wrote:
    [color=blue]
    > 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(myR esponseStream) 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(sende r as object, e as Eventargs)
    >
    > Dim wRequest As System.Net.Http WebRequest
    > Dim wResponse As System.Net.Http WebResponse
    > Dim StreamHandler As System.IO.Strea mReader
    > Dim xmlDoc As New System.Xml.XmlD ocument
    >
    > Try
    > Dim URL As String = "http://localhost/aspnet/process.asp"
    > wRequest = System.Net.WebR equest.Create(U RL)
    > wRequest.Header s.Add("Man", "GET " & URL)
    > wResponse = CType(wRequest. GetResponse,
    > System.Net.WebR esponse)
    > If wRequest.HaveRe sponse Then
    > if wResponse.Statu sCode = Net.HttpStatusC ode.OK Then
    > streamHandler = New
    > System.IO.Strea mReader(wRespon se.GetResponseS tream())
    > xmlDoc.LoadXml( StreamHandler.R eadToEnd)
    > MsgBox("[--------" & xmlDoc.InnerTex t & "-------]")
    > End If
    > End If[/color]


    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 );
    [color=blue]
    > 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>proces s</title></head>
    > <body>[/color]

    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/

    Comment

    • Keith A. Lewis

      #3
      Re: How to Remove Http header from http response

      mehtavb@hotmail .com (Vivek Mehta) writes in article <14394a00.04081 01955.5b5838aa@ posting.google. com> dated 10 Aug 2004 20:55:18 -0700:[color=blue]
      >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(my ResponseStream) to break because the test preceding the
      >XML makes the xml invalid.[/color]

      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.

      Comment

      • Vivek Mehta

        #4
        Re: How to Remove Http header from http response

        Martin Honnen <mahotrash@yaho o.de> wrote in message news:<411a0e4c$ 1@olaf.komtel.n et>...[color=blue]
        > Vivek Mehta wrote:
        >[color=green]
        > > 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(myR esponseStream) 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(sende r as object, e as Eventargs)
        > >
        > > Dim wRequest As System.Net.Http WebRequest
        > > Dim wResponse As System.Net.Http WebResponse
        > > Dim StreamHandler As System.IO.Strea mReader
        > > Dim xmlDoc As New System.Xml.XmlD ocument
        > >
        > > Try
        > > Dim URL As String = "http://localhost/aspnet/process.asp"
        > > wRequest = System.Net.WebR equest.Create(U RL)
        > > wRequest.Header s.Add("Man", "GET " & URL)
        > > wResponse = CType(wRequest. GetResponse,
        > > System.Net.WebR esponse)
        > > If wRequest.HaveRe sponse Then
        > > if wResponse.Statu sCode = Net.HttpStatusC ode.OK Then
        > > streamHandler = New
        > > System.IO.Strea mReader(wRespon se.GetResponseS tream())
        > > xmlDoc.LoadXml( StreamHandler.R eadToEnd)
        > > MsgBox("[--------" & xmlDoc.InnerTex t & "-------]")
        > > End If
        > > End If[/color]
        >
        >
        > 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 );
        >[color=green]
        > > 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>proces s</title></head>
        > > <body>[/color]
        >
        > If you want to output XML then you can't have the HTML in your page,
        > throw that out.[/color]


        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.time out 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.

        Comment

        Working...