Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLHTTP POST doesn't POST (does GET instead)

Status
Not open for further replies.

Spork52

Programmer
Nov 20, 2007
134
US
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::

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?
 
Correction:

xml.setRequestHeader "Content-Type", "application/x-
should not be commented out. Although I get (ha ha) the same result regardless.
 
>xml.send ""
[tt]xml.send "field1=test1&field2=test2&field3=test3"[/tt]

There are here and there some problems in detail, but I'll leave them to yourself to rectify.
 
So, I thought everything was okay until I tried it on a bunch of browsers. They all work if there is nothing else on the page, but as soon as I tried adding "please wait" animations and other HTML, some browsers stopped working. It seem highly dependent on what and where the HTML, etc. is in relation to the ASP script. Any advice on what will work on all browsers? I am posting to a payment gateway which then posts back transaction results and data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top