Trying to get an ASP page to submit a form, via an XMLHTTP object, to another ASP page, and return the processed response.
On my local machine, (although using full URLs, not relative paths), it works.
On a live server, the response page returns a HTTP 400 error: "Bad Request (Invalid Hostname)"
My code:
http_test1.asp :
http_test2.asp :
I've tried adding:
xmlhttp.setRequestHeader "Host", "****URL****"
and:
xmlhttp.setRequestHeader "Content-length", len(strForm) 'apparently some servers are unhappy if you omit this
... with no effect. Any suggestions?
On my local machine, (although using full URLs, not relative paths), it works.
On a live server, the response page returns a HTTP 400 error: "Bad Request (Invalid Hostname)"
My code:
http_test1.asp :
Code:
<% if request.form & "" <> "" then dim strForm : strForm = Request.Form Response.Write("<br/>Submitting request:<br/>" & strForm & "<br/><br/>" & vbCrLf) On Error Resume Next dim xmlhttp set xmlhttp = server.createobject("MSXML2.ServerXMLHTTP") xmlhttp.open "POST","http://****URL****/http_test2.asp", false xmlhttp.setRequestHeader "lastCached", Date xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.send strForm Response.Write("<br/>Response status: " & xmlhttp.status & "<br />") Response.Write("<br/>Response headers: " & xmlhttp.getAllResponseHeaders() & "<br />") Response.Write("<br/>Response text: " & xmlhttp.responseText & "<br/>") if Err.Number > 0 then Response.Write("Error: " & Err.number & "(" + Err.description & ")") end if else %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script type="text/javascript"> function switchAction(oForm, sAction){ oForm.action = sAction; oForm.submit(); } </script> </head> <body> <form name="f1" id="f1" action="http://****URL****/http_test1.asp" method="post"> <input type="text" name="t1" value="t1"/><br/> <input type="text" name="t2" value="t2"/><br/> <input type="text" name="t3" value="t3"/><br/> <input type="text" name="t4" value="t4"/><br/> <input type="button" onClick="switchAction(this.form, 'http://****URL****/http_test1.asp')" value="Send via XMLHTTP"/> <input type="button" onClick="switchAction(this.form, 'http://****URL****/http_test2.asp')" value="Send via HTML form"/> </form> </body> </html> <% end if %>
http_test2.asp :
Code:
<% if request.form & "" <> "" then response.write("<br/>You posted:<br/>" & vbCrLf) for each formItem in request.form response.write(formItem & " = " & request.form(formItem) & "<br/>" & vbCrLf) next end if %>

I've tried adding:
xmlhttp.setRequestHeader "Host", "****URL****"
and:
xmlhttp.setRequestHeader "Content-length", len(strForm) 'apparently some servers are unhappy if you omit this
... with no effect. Any suggestions?