I need to POST
data to a url in the middle of a script.
process.asp
: I need to PO
Most form action pages accept data as a POST.
Function postFormData(url, data)
Dim xhr : Set xhr = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xhr.open "POST", url, false
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xhr.send Data
If xhr.Status = 200 Then
postFormData = xhr.ResponseText
Else
Err.Raise 1001, "postFormData", "Post to " & url & " failed with " & xhr.Status
End If
End Function
When creating the data url encoding is needed on the data values. Since ASPs Server.URLEncode method only does path encoding and not component encoding you need to replace out / characters with %2F
Function URLEncodeComponent(value)
URLEncodeComponent = Server.URLEncode(value)
URLEncodeComponent = Replace(URLEncodeComponent, "/", "%2F")
End Function