469,626 Members | 883 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.


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:


<form name="xConnectForm" method="POST"

<input type="hidden" name="XMLDOC" value="<?xml
name='datestart'>2006-10-27 20:50:00</input><input
name='dateend'>2006-11-27 20:55:00</input></report></xconnect>"/>

<input type="submit" />



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=" &
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

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?

John Braham

Dec 6 '06 #1
1 6734
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

And my revised posting code is now:

Dim webClient As WebClient = New WebClient()
Dim response As Byte() = webClient.UploadData(TextBox1.Text,
"POST", Encoding.UTF8.GetBytes("XMLDOC=" & TextBox2.Text))

TextBox3.Text &= "Response: " & vbCrLf &

Which is just a tad shorter,

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

John Braham

Dec 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by KhanyBoy | last post: by
2 posts views Thread by Chris Cairns | last post: by
4 posts views Thread by Al Cadalzo | last post: by
reply views Thread by Dan Corkum | last post: by
2 posts views Thread by LD | last post: by
1 post views Thread by rh1200la | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.