Connecting Tech Pros Worldwide Help | Site Map

How to make a POST request in vb.net

Newbie
 
Join Date: May 2009
Posts: 5
#1: Oct 8 '09
Hi. I am using visual studio 8, using vb.net. I am trying without success to make a post request to a web form as shown below.


<?xml version="1.0" encoding="UTF-8"?><postBetOrder xmlns="urn:betfair:games:api:v1"marketId="2568540" round="1" currency="GBP">
<betPlace>
<bidType>BACK</bidType>
<price>2.5</price>
<size>2.50</size>
<selectionId>658440</selectionId>
</betPlace>


I encode the information using 'HttpUtility.UrlEncode' and I use
'myWebRequest.ContentLength = bytedata.Length' to get the length and then I use
postStream = myWebRequest.GetRequestStream()
postStream.Write(bytedata, 0, bytedata.Length)
to post, but keep getting a 'premature end of file' error.
I dont think that I am posting the right information. Am i supposed to post just the information or do I post the the tags and the information? This is all very new to me and I really am stuck so if anyone can help I'd be most grateful. Thanks for all and any contributions.
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,264
#2: Oct 10 '09

re: How to make a POST request in vb.net


Quote:

Originally Posted by smileyc View Post

Hi. I am using visual studio 8, using vb.net. I am trying without success to make a post request to a web form as shown below.

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?><postBetOrder xmlns="urn:betfair:games:api:v1"marketId="2568540" round="1" currency="GBP">
  2. <betPlace>
  3. <bidType>BACK</bidType>
  4. <price>2.5</price>
  5. <size>2.50</size>
  6. <selectionId>658440</selectionId>
  7. </betPlace>
  8.  
  9.  
I encode the information using 'HttpUtility.UrlEncode' and I use
'myWebRequest.ContentLength = bytedata.Length' to get the length and then I use
postStream = myWebRequest.GetRequestStream()
postStream.Write(bytedata, 0, bytedata.Length)
to post, but keep getting a 'premature end of file' error.
I dont think that I am posting the right information. Am i supposed to post just the information or do I post the the tags and the information? This is all very new to me and I really am stuck so if anyone can help I'd be most grateful. Thanks for all and any contributions.


I am going to send over to .net for a closer look, you'll probably get more hits there:-)
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#3: Oct 12 '09

re: How to make a POST request in vb.net


POST requests can be done a number of ways.
In HTML using a form section
In javascript using the XMLHttpRequest object
In backend code vbnet(or any .NET language) using the HttpWebRequest object

Be sure to set the method to "POST" as it defaults to "GET"
Reply

Tags
https, post, vb.net