473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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
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
Jul 21 '05 #1
0 988

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keith Selbee | last post by:
I am trying to submit data to a webpage in the form of a post and my code is below. It is a function that takes a url and the post content as strings and then performs the post. But as soon as I...
3
by: Stephane | last post by:
Hi, I'm trying to use PayPal and its Instant Payment Notification. In short, when a payment is made, PayPal send a post to my server and I post it back to PayPal. I'm using WebRequest to do...
4
by: Terry | last post by:
Hello, I am trying to get a response for an .aspx page in my current project (same virtual directory) by using WebRequest.GetResponse but I keep getting a exception with "500 Internal server...
0
by: MARTIN LANNY | last post by:
Hi everyone, To bring you in the picture: I have the function to grab the html content from the page. Function requires only URL and Time Delay variables. Url, which I am submitting to this...
0
by: Neal | last post by:
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...
5
by: archana | last post by:
Hi all i am having application which is using asychronous web request. At a time i am processing 5 urls asynchronously. Application working properly for 5 asynchronous call. But sometimes CPU...
4
by: Savas Ates | last post by:
I have a vb.net web application. I want to post some variables to another web page and take some values back and process them. This is codes in my target url. I should post "langpair" cariable...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
6
by: matt | last post by:
hello, i am having trouble doing something. when a user triggers a certain event in my app, i need to initiate another web request to one of my other webpages, programmatically. currently, i do...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.