I am trying to use ASP and XMLHTTP (not javascript) to POST form data, but instead the code sends the data as a GET (as if it is in the URL querystring). Here's my code:
send.asp::
receive.asp:
The result, when browsing to send.asp is:
Which means that the data is sent as a GET, not as a POST.
I have to POST the data to a payment gateway, so I need to get this working. Is this just the way it is, or is there some error in my code, or is there something wrong with the server?
send.asp::
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
'set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.open "POST", "[URL unfurl="true"]http://www.mysite.com/receive.asp?field1=test1&field2=test2&field3=test3",[/URL] False
'xml.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
xml.send ""
if xml.readyState <> 4 then
xml.waitForResponse 30 'wait up to 30 seconds for xml
End If
if Err.Number <> 0 then
output_string = "Server error.<br>Err.Source: " & Err.Source & "<br>Err.Number: " & Err.Number & "<br>Err.Description: " & Err.Description
else
'Check HTTP readyState status: 4 means . . . okay?
'Check HTTP response status: 200 means HTTP request was successful.
If (xml.readyState <> 4) OR (xml.Status <> 200) Then
if xml.readyState <> 4 then
output_string = "<br>Ready State: " & xml.readyState
end if
if xml.Status <> 200 then
output_string = output_string & "<br>Status: " & xml.Status & ""
end if
xml.Abort
Else
output_string = xml.responseText
End If
end if
set xml = nothing
On Error Goto 0
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<%
Response.Write output_string
%>
</body>
</html>
receive.asp:
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
field1 = request.form("field1")
field2 = request.form("field2")
field3 = request.form("field3")
Response.Write "<p>request.form:"
Response.Write "<br>1: " & field1 & "<br>2: " & field2 & "<br>3: " & field3
field1 = request.querystring("field1")
field2 = request.querystring("field2")
field3 = request.querystring("field3")
Response.Write "<p>request.querystring:"
Response.Write "<br>1: " & field1 & "<br>2: " & field2 & "<br>3: " & field3
%>
The result, when browsing to send.asp is:
Code:
request.form:
1:
2:
3:
request.querystring:
1: test1
2: test2
3: test3
Which means that the data is sent as a GET, not as a POST.
I have to POST the data to a payment gateway, so I need to get this working. Is this just the way it is, or is there some error in my code, or is there something wrong with the server?