ASP/VBScript Form Post Handling

X

xernoth

Hi there,

Just a quick question. I'm more familiar with C# and ASP.NET but need
to use ASP/VBScript for a quick project.

I have a form that uploads content to a server not managed by us. When
the form is filled in and posted, the response from the server is an
XML response. However when that happens, I'm not longer at my asp
page, I'm redirected the XML response URL that's managed by the third
party server.

I have two questions are a result:
1) I understand I can use XmlHTTP to simulate a form and post that
using XmlHttp.Send String. However, the form that uploads content is
quite complex. It contains 4 type=text input fields, 1 textarea field,
and a type=file field.
How would I specify all this in the XmlHttp.Send String? More
specifically, how would I specify the type=file field? When using a
proxy trace application to manually intercept my post, the type=file
field looks like this:
Content-Disposition: form-data; name="file1"; filename="C:
\mediaexample.wmv"
Content-Type: video/x-ms-wmv

2) Is there anyway to specify a html form in the XmlHttp.Send? So
instead of having to build a string with all the form information,
just reference the form name and Send that instead?

Any ideas would be appreciate. For the record, I've done extensive
browsing, and although I've come across useful information, nothing
that quite answers my dilemma. If I'm overlooking the obvious, please
let me know.

Thanks.
 
A

Anthony Jones

Hi there,

Just a quick question. I'm more familiar with C# and ASP.NET but need
to use ASP/VBScript for a quick project.

I have a form that uploads content to a server not managed by us. When
the form is filled in and posted, the response from the server is an
XML response. However when that happens, I'm not longer at my asp
page, I'm redirected the XML response URL that's managed by the third
party server.

I have two questions are a result:
1) I understand I can use XmlHTTP to simulate a form and post that
using XmlHttp.Send String. However, the form that uploads content is
quite complex. It contains 4 type=text input fields, 1 textarea field,
and a type=file field.
How would I specify all this in the XmlHttp.Send String? More
specifically, how would I specify the type=file field? When using a
proxy trace application to manually intercept my post, the type=file
field looks like this:
Content-Disposition: form-data; name="file1"; filename="C:
\mediaexample.wmv"
Content-Type: video/x-ms-wmv

2) Is there anyway to specify a html form in the XmlHttp.Send? So
instead of having to build a string with all the form information,
just reference the form name and Send that instead?

Any ideas would be appreciate. For the record, I've done extensive
browsing, and although I've come across useful information, nothing
that quite answers my dilemma. If I'm overlooking the obvious, please
let me know.

Question 2 first: No.

Question1 :

Whilst it is quite possible to emulate a mime mulltipart form post with
XmlHttp send the problem will be the file data field. The client side code
will need to be able to read the local file in order to encode its bytes
into the post. However to do that without some custom component support
would require the user to reduce IE security to what is likely to be an
unacceptably weak level.

One option would be to make the action of the form point at a page on your
site and have that repeat the post to the third party. There are number of
downsides such as the extra bandwidth load on your site and extra complexity
if the third party requires session management.
 
O

Old Pedant

2) Is there anyway to specify a html form in the XmlHttp.Send? So
instead of having to build a string with all the form information,
just reference the form name and Send that instead?

Why not just do
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "POST", "...url..."
http.Send Request.Form
???

That is, just "forward" the entire contens of the form to the remote site??
 
A

Anthony Jones

Old Pedant said:
Why not just do
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "POST", "...url..."
http.Send Request.Form
???

That is, just "forward" the entire contens of the form to the remote site??


The won't work in this case because in order to upload a file the form
encoding needs to be multipart/form-data. The ASP Form object can't read
that type of form data.

I was thinking of something more raw than that :-

Dim xhr : Set xhr = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")

xhr.Open "POST", "..url..", false
xhr.setRequestHeader "Content-Type",
Request.ServerVariables("HTTP_CONTENT_TYPE")
xhr.send Request.BinaryRead(Request.TotalBytes)

Now the xhr.ResponseXML can be transformed to respond to the client.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,738
Latest member
TiffinyHol

Latest Threads

Top