473,473 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB.NET HTTP Form Post

I have a slight wall headbutter which I'm hoping someone will have an
idea for (I'd be very grateful!).

Basically I'm trying to make a form post to an asp page programatically
from within VB.NET 2005, the only data posted is one hidden field
XMLDOC, which contains an xml file which the receiving page will
respond to... I know, it's not a great way of doing this... I know I
should be using a web service, but basically this is the way I have to
interact with this page.

If I build an asp page to do this it works:

<HTML>
<HEAD></HEAD>
<BODY>

<form name="xConnectForm" method="POST"
action="http://campaigner.concepglobal.com/xconnect/xconnect.asp">

<input type="hidden" name="XMLDOC" value="<?xml
version='1.0'?><xconnect><interface><![CDATA[SERVER]]></interface><user><username><![CDATA[username]]></username><password><![CDATA[password]]></password></user><report><id>account_recipientactivity</id><input
name='datestart'>2006-10-27 20:50:00</input><input
name='dateend'>2006-11-27 20:55:00</input></report></xconnect>"/>

<input type="submit" />

</form>

</BODY>
</HTML>

Hitting submit on this form successfully causes the receiving page to
return the response, so what I've tried to do is translate this logic
into VB.NET code as follows:

' textbox1 has the url
' textbox2 has the request xml
' textbox3 is blank for seeing the response xml
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes("XMLDOC=" &
TextBox2.Text)
Dim res As Byte() = web.UploadData(TextBox1.Text, "POST", d)

TextBox3.Text = "Response:" & System.Text.Encoding.ASCII.GetString(res)
& vbCrLf & vbCrLf
TextBox3.Text &= "Request:" & System.Text.Encoding.ASCII.GetString(d)

I've tried various other (longer and more complicated) examples of http
posting, all of which cause the reveiving page to fall over with an XML
parsing error (whereas the page process the earlier asp post example
correctly).

Now I'm assuming it's some kind of encoding issue, all the examples I
have encode the XML into the url string.

Basically what I'm asking is does anyone know of a way I can simulate
what I'm doing in the asp example, make a http post in the exact same
manner as if it was done from the browser?

Thanks,
John Braham

Dec 6 '06 #1
1 6906
Ok, partially answered my own question now, turns out (from setting up
a little test rig) that my encoding is to blame, it's stripping out all
the whitespace, which messes it up when the xml attribute names get
joined onto the node names!

Now all I have to figure out is how to encode it and not bugger up the
xml!

And my revised posting code is now:

Dim webClient As WebClient = New WebClient()
webClient.Headers.Add("Content-Type",
"application/x-www-form-urlencoded")
Dim response As Byte() = webClient.UploadData(TextBox1.Text,
"POST", Encoding.UTF8.GetBytes("XMLDOC=" & TextBox2.Text))

TextBox3.Text &= "Response: " & vbCrLf &
System.Text.Encoding.UTF8.GetString(response)

Which is just a tad shorter,

if anyone has any quick ideas on the whitespace issue I'd still be very
pleased to hear.

Thanks,
John Braham

Dec 7 '06 #2

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

Similar topics

1
by: KhanyBoy | last post by:
Hi, heres my problem. I can consume a soap server in php within a browser by 'post'ing a form variable that contains XML - no problem. However, if I want to use the php command line to send...
2
by: Chris Cairns | last post by:
I have a basic form that POSTs data to a web server. The web server then replys with a string response. It goes something like this <FORM METHOD=POST...
1
by: Dan Corkum | last post by:
Good morning. I am working on an issue that is just baffling me. I have developed an .aspx page that receives an http form post that has a "file" attribute. When I do testing with a test post...
4
by: Al Cadalzo | last post by:
I'm trying to simulate a form post (i.e. Method="POST"). The FORM POST I'm trying to simulate is similar to this: <FORM NAME=SearchForm METHOD=POST ACTION=Search> <SELECT name="criteriaA" >...
0
by: Dan Corkum | last post by:
Good morning. I am working on an issue that is just baffling me. I have developed an .aspx page that receives an http form post that has a "file" attribute. When I do testing with a test post...
2
by: LD | last post by:
Hi, I am trying to upload a zip file and other form data elements to a server and get a response. The server keeps responding with Malformed Multipart Post. Can anyone see what might be wrong...
1
by: rh1200la | last post by:
Hi all...i'm trying to do a form post in my codebehind file using this method: public static string HttpPost(string URI, string Parameters) { System.Net.WebRequest req =...
10
by: eggie5 | last post by:
Is it possible to get a file without using a form post? I want to get the data (bytes) of a file, text or binary, and just save it to a variable. Similar to the post body of a form that has a...
0
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.