what's wrong with xml post code?

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

    what's wrong with xml post code?

    Hi
    Trying to get this code to work for http xml post.
    I need the post to be xml (doc.outerxml) sent in single key name as stream.
    The following is the post code and code for receiving the request.
    When it hits the "myresponse = myrequest.GetRe sponse()" in the post code -
    I'm getting following error:
    "The remote server returned an error: (500) Internal Server Error".
    I don't know if I have something wrong with the post or receiving it on the
    other end.
    Right now I'm trying to write it in .net 1.1.
    Any help will be greatly appreciated.
    Thanks,
    Cindy

    Dim url As String = "http://someplace.aspx"
    Dim myrequest As System.Net.WebR equest = Nothing
    Dim myresponse As System.Net.WebR esponse = Nothing
    Try
    ' Create a request using a URL that can receive a post.
    myrequest = System.Net.WebR equest.Create(u rl)
    ' Set the Method property of the request to POST.
    myrequest.Metho d = "POST"
    ' Set the ContentType property of the WebRequest.
    myrequest.Conte ntType = "applicatio n/x-www-form-urlencoded"
    ' Create POST data and convert it to a byte array.
    Dim vxml = "Interface_ 2=" + HttpUtility.Url Encode(Doc.Oute rXml)
    Dim byteArray As Byte() =
    System.Text.Enc oding.UTF8.GetB ytes(vxml)
    ' Set the ContentLength property of the WebRequest.
    myrequest.Conte ntLength = byteArray.Lengt h
    ' Get the request stream.
    Dim dataStream As System.io.Strea m =
    myrequest.GetRe questStream()
    ' Write the data to the request stream.
    dataStream.Writ e(byteArray, 0, byteArray.Lengt h)
    ' Close the Stream object.
    dataStream.Clos e()
    ' Get the response.
    myresponse = myrequest.GetRe sponse() 'error occurs here
    Catch ex As Exception
    Throw ex
    Finally
    ' Closed streams
    If Not myrequest Is Nothing Then
    myrequest.GetRe questStream().C lose()
    If Not myresponse Is Nothing Then
    myresponse.GetR esponseStream() .Close()
    End Try

    Code for receiving the post:
    Dim strReader As System.IO.Strin gReader = Nothing
    Dim Reader As System.Xml.XmlT extReader = Nothing
    Response.Conten tType = "applicatio n/x-www-form-urlencoded"
    Response.Clear( )
    Try
    strReader = New
    System.IO.Strin gReader(Request .Form("Interfac e_2"))
    Reader = New System.Xml.XmlT extReader(strRe ader)
    Do While Reader.Read()


  • Bjoern Hoehrmann

    #2
    Re: what's wrong with xml post code?

    * CindyH wrote in microsoft.publi c.dotnet.xml:
    >Trying to get this code to work for http xml post.
    >I need the post to be xml (doc.outerxml) sent in single key name as stream.
    >The following is the post code and code for receiving the request.
    >When it hits the "myresponse = myrequest.GetRe sponse()" in the post code -
    >I'm getting following error:
    >"The remote server returned an error: (500) Internal Server Error".
    This means something has gone wrong on the server. It's quite possible
    that this is a result of an error on your side, but without checking the
    server (e.g., the logs, read source code of the remote application) it's
    not possible to know for sure. You don't say, for example, whether this
    works fine when using some other application to access the resource.
    --
    Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

    Comment

    • Cindy H

      #3
      Re: what's wrong with xml post code?

      I'm using xmlreader, not a xmltextreader and moved it to .net 2.0, but still
      no luck.



      "CindyH" <chenschel@new. rr.comwrote in message
      news:%23n1M9Pvs IHA.3780@TK2MSF TNGP03.phx.gbl. ..
      Hi
      Trying to get this code to work for http xml post.
      I need the post to be xml (doc.outerxml) sent in single key name as
      stream.
      The following is the post code and code for receiving the request.
      When it hits the "myresponse = myrequest.GetRe sponse()" in the post code -
      I'm getting following error:
      "The remote server returned an error: (500) Internal Server Error".
      I don't know if I have something wrong with the post or receiving it on
      the other end.
      Right now I'm trying to write it in .net 1.1.
      Any help will be greatly appreciated.
      Thanks,
      Cindy
      >
      Dim url As String = "http://someplace.aspx"
      Dim myrequest As System.Net.WebR equest = Nothing
      Dim myresponse As System.Net.WebR esponse = Nothing
      Try
      ' Create a request using a URL that can receive a post.
      myrequest = System.Net.WebR equest.Create(u rl)
      ' Set the Method property of the request to POST.
      myrequest.Metho d = "POST"
      ' Set the ContentType property of the WebRequest.
      myrequest.Conte ntType = "applicatio n/x-www-form-urlencoded"
      ' Create POST data and convert it to a byte array.
      Dim vxml = "Interface_ 2=" + HttpUtility.Url Encode(Doc.Oute rXml)
      Dim byteArray As Byte() =
      System.Text.Enc oding.UTF8.GetB ytes(vxml)
      ' Set the ContentLength property of the WebRequest.
      myrequest.Conte ntLength = byteArray.Lengt h
      ' Get the request stream.
      Dim dataStream As System.io.Strea m =
      myrequest.GetRe questStream()
      ' Write the data to the request stream.
      dataStream.Writ e(byteArray, 0, byteArray.Lengt h)
      ' Close the Stream object.
      dataStream.Clos e()
      ' Get the response.
      myresponse = myrequest.GetRe sponse() 'error occurs here
      Catch ex As Exception
      Throw ex
      Finally
      ' Closed streams
      If Not myrequest Is Nothing Then
      myrequest.GetRe questStream().C lose()
      If Not myresponse Is Nothing Then
      myresponse.GetR esponseStream() .Close()
      End Try
      >
      Code for receiving the post:
      Dim strReader As System.IO.Strin gReader = Nothing
      Dim Reader As System.Xml.XmlT extReader = Nothing
      Response.Conten tType = "applicatio n/x-www-form-urlencoded"
      Response.Clear( )
      Try
      strReader = New
      System.IO.Strin gReader(Request .Form("Interfac e_2"))
      Reader = New System.Xml.XmlT extReader(strRe ader)
      Do While Reader.Read()
      >

      Comment

      Working...