471,337 Members | 957 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

WebRequest: Post or Get .. to retrieve XML from an API??

Hi All

When using a webrequest Post or Get , I keep getting an empty response
stream (it is supposed to be an XML file returned via a call to some Systems

If i paste the URL (created as below) into the IE adress bar and invoke, it
works fine
but I return nothing from the Request..

Settings or code problems ??

I use the following
req = WebRequest.Create(url)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim strResult As String
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.Su bstring(i, payload.Length -
Exit While
End If

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

' '-- Response Object, http web hdrs stuff
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()
encode = System.Text.Encoding.GetEncoding("utf-8")
sr = New StreamReader(ReceiveStream, encode)
Dim read(256) As Char
Dim count As Integer = sr.Read(read, 0, 256)
Dim ii As Integer
Dim responseText As String
responseText = sr.ReadToEnd()

''''''' or (which reults in content length = -1 and the "Invalid data at
root" error message)

Dim doc As System.Xml.XmlDocument = New
Neal Rogers
University of Cape Town
Jul 21 '05 #1
0 926

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Keith Selbee | last post: by
3 posts views Thread by Stephane | last post: by
reply views Thread by MARTIN LANNY | last post: by
4 posts views Thread by Savas Ates | last post: by
6 posts views Thread by matt | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.