J
John Braham
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
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