all groups > dotnet xml > february 2005 >
You're in the

dotnet xml

group:

Totally lost...Retrieving XML from WebRequest/Response..problems


Totally lost...Retrieving XML from WebRequest/Response..problems Neal
2/25/2005 12:13:02 AM
dotnet xml: Hi All

I post a WebRequest, and the response is supposed to be delivered in XML
format.
posting the request in the browser address bar does return it..
ie

<?xml version="1.0" standalone="no" ?>
' <!DOCTYPE homearea (View Source for full doctype...)>
'- <homearea base="http://webedu.its.uct.ac.za:80"
top_bar_background="#51657b" top_bar_title="#ffffff"
.................................................................
..........................................
</homearea>

I Using the following
Dim result As WebResponse
Dim req As WebRequest
Dim RequestStream As Stream
Dim ReceiveStream As Stream
Dim encode As Encoding
Dim sr As StreamReader
Dim SomeBytes() As Byte
Dim UrlEncoded As New StringBuilder()
Dim reserved() As Char = {ChrW(63), ChrW(61), ChrW(38)}

req = WebRequest.Create(url)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded" 'The
ContentType property contains the media type of the request

Dim strResult As String

Try
Dim i As Integer = 0
If payload <> Nothing Then
Dim j As Integer


While i < payload.Length
j = payload.IndexOfAny(reserved, i)
If j = -1 Then

UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, payload.Length -
i)))
Exit While
End If

UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, j - i)))
UrlEncoded.Append(payload.Substring(j, 1))
i = j + 1
End While
SomeBytes =
System.Text.Encoding.UTF8.GetBytes(UrlEncoded.ToString())
req.ContentLength = SomeBytes.Length
RequestStream = req.GetRequestStream()
RequestStream.Write(SomeBytes, 0, SomeBytes.Length)
RequestStream.Close()
Else
req.ContentLength = 0
End If

I get the error
" there is invalid data at the root level, line 1,position 1"

when using XML Reader or XMLValidating Reader
Dim xr As New XmlTextReader(New StreamReader(ReceiveStream,
encode))
xr.Normalization = False/True
While xr.Read
strResult = strResult & xr.ReadInnerXml
'## error: there is invalid data at the root level, line
1,position 1
End While
End If


Any and all help will be appreciated,
this stuff is very new to me, and seriously fructrating.
TIA
--
Neal Rogers
Re: Totally lost...Retrieving XML from WebRequest/Response..problems Dino Chiesa [Microsoft]
3/1/2005 1:09:49 PM
I just normally do

System.Xml.XmlDocument doc= new System.Xml.XmlDocument();
doc.Load(request.GetResponse().GetResponseStream());

-D


[quoted text, click to view]

AddThis Social Bookmark Button