473,405 Members | 2,160 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,405 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
Nov 22 '05 #1
0 935

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

Similar topics

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...
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...
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...
3
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.