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
GetXMLFileAPI)
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 ??
thanks
I use the following
req = WebRequest.Create(url)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
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.Su bstring(i, payload.Length -
i)))
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)
RequestStream.Close()
Else
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
System.Xml.XmlDocument()
doc.Load(req.GetResponse().GetResponseStream())
--
Neal Rogers
University of Cape Town