HttpWebRequest adding junk characters

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default HttpWebRequest adding junk characters

    I am trying to invoke a remote Web Service that accepts XML data over https
    but the server is returning a "The data at the root level is invalid. Line
    1, position 1." error. I checked with the provider and he said that they
    were receiving following on their server... Notice the weird junk characters
    at the front...

    <?xml version="1.0" encoding="utf-8"?>
    <request><name>blah</blah><address>blah blah</address></request>

    I checked the XML I am sending by writing it to a file instead of sending
    over http and it was fine. I then created an ASP.NET web application that
    took a request and wrote it out to a file. This also worked fine and there
    were no junk characters in it. So I think the XML is being created correctly
    and the only time there is a problem is when I am invoking a remote service
    over https. Does anyone why the remote server is getting those junk
    characters? Any suggestions are welcome...

    I am using the following code to create my httpWebRequest

    httpWebRequest = System.Net.WebRequest.Create([url]https://blah.blah.com[/url])
    httpWebRequest.Method = "POST"

    httpWebRequest.ContentType = "text/xml"

    Dim oProxy As WebProxy = WebProxy.GetDefaultProxy()

    oProxy.Credentials = CredentialCache.DefaultCredentials

    httpWebRequest.Proxy = oProxy

    httpWebRequest.KeepAlive = False

    httpWebRequest.ProtocolVersion = New System.Version("1.0")

    httpWebRequest.Timeout = 12000


    and following code to invoke the Web service

    xmlWriter = New XmlTextWriter(httpRequest.GetRequestStream(),
    System.Text.Encoding.UTF8)

    With xmlWriter

    ..WriteStartDocument()

    ..WriteStartElement("request")

    ..WriteElementString("name", "blah")

    ..WriteElementString("address", "blah blah")

    ..WriteEndElement()

    ..WriteEndDocument()

    ..Flush()

    ..Close()

    End With

    xmlReader = New XmlTextReader(httpRequest.GetResponse().GetRespons eStream())

    Thanks in advance,

    Sandeep






    Sandeep Guest

  2. Similar Questions and Discussions

    1. Contribute Adding Characters to Contact Text
      When I edit a web page in Contribute, I notice that at the bottom of the page that I publish, before the copyright information that's on every page...
    2. XML::Twig parser junk.
      Hi, I'm trying to use XML::Twig to insert dates into <unitdate> tags to create an EAD finding aid, but I'm running into a strang XML::Twig parser...
    3. XML error: junk after document element
      I am trying to parse and xml document: <?xml version="1.0"?> <!DOCTYPE PrequalResponse PUBLIC "-//New Edge Networks//DTD Pilot Prequalification...
    4. One Man's Junk
      Some cameras which were rescued from dusty shelves and the junk heap. http://www.oceans-away.com/camera/
    5. Junk mail on the list.
      I'm getting a lot of junk mail that is addressed to this list. Am I the only one getting this stuff? alex -- To UNSUBSCRIBE, email to...
  3. #2

    Default Re: HttpWebRequest adding junk characters

    Problem solved. It was the xmlTextWriter that was creating the problem. I
    directly wrote a string out to the server and it worked fine.


    "Sandeep" <nojunk@nojunk.com> wrote in message
    news:ugpw3VvgFHA.2852@TK2MSFTNGP15.phx.gbl...
    >I am trying to invoke a remote Web Service that accepts XML data over https
    >but the server is returning a "The data at the root level is invalid. Line
    >1, position 1." error. I checked with the provider and he said that they
    >were receiving following on their server... Notice the weird junk
    >characters at the front...
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <request><name>blah</blah><address>blah blah</address></request>
    >
    > I checked the XML I am sending by writing it to a file instead of sending
    > over http and it was fine. I then created an ASP.NET web application that
    > took a request and wrote it out to a file. This also worked fine and there
    > were no junk characters in it. So I think the XML is being created
    > correctly and the only time there is a problem is when I am invoking a
    > remote service over https. Does anyone why the remote server is getting
    > those junk characters? Any suggestions are welcome...
    >
    > I am using the following code to create my httpWebRequest
    >
    > httpWebRequest = System.Net.WebRequest.Create([url]https://blah.blah.com[/url])
    > httpWebRequest.Method = "POST"
    >
    > httpWebRequest.ContentType = "text/xml"
    >
    > Dim oProxy As WebProxy = WebProxy.GetDefaultProxy()
    >
    > oProxy.Credentials = CredentialCache.DefaultCredentials
    >
    > httpWebRequest.Proxy = oProxy
    >
    > httpWebRequest.KeepAlive = False
    >
    > httpWebRequest.ProtocolVersion = New System.Version("1.0")
    >
    > httpWebRequest.Timeout = 12000
    >
    >
    > and following code to invoke the Web service
    >
    > xmlWriter = New XmlTextWriter(httpRequest.GetRequestStream(),
    > System.Text.Encoding.UTF8)
    >
    > With xmlWriter
    >
    > .WriteStartDocument()
    >
    > .WriteStartElement("request")
    >
    > .WriteElementString("name", "blah")
    >
    > .WriteElementString("address", "blah blah")
    >
    > .WriteEndElement()
    >
    > .WriteEndDocument()
    >
    > .Flush()
    >
    > .Close()
    >
    > End With
    >
    > xmlReader = New
    > XmlTextReader(httpRequest.GetResponse().GetRespons eStream())
    >
    > Thanks in advance,
    >
    > Sandeep
    >
    >
    >
    >
    >
    >

    Sandeep Guest

  4. #3

    Default Re: HttpWebRequest adding junk characters


    Try using an encoding other than System.Text.Encoding.UTF8.


    ************************************************** ********************
    Sent via Fuzzy Software @ [url]http://www.fuzzysoftware.com/[/url]
    Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
    dj_axl@yahoo.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139