I am trying to duplicate the Visual Basic and Microsoft WinHTTP example below in PB. I have reviewed the WINHTTP Flat API Examples. Seems like I should be able to do something similar. Does anyone know if the code in the VB example below can be accomplished with
WinHTTPOpen
WinHTTPConnect
WINHTTPOpenRequest
WinHTTPAddRequestHeaders
WinHTTPSendRequest
To process the repsonse call
WinHTTPReceiveResponse???
The following is an example of how to submit a request string to PAYware Connect using Visual Basic and Microsoft WinHTTP Services version 5.1 (winhttp.dll):
Dim objHTTP As New WinHttp.WinHttpRequest
strURL = https://APIDemo.IPCharge.net/IPCHAPI/RH.aspx obj
HTTP.Open "POST", strURL, False obj
HTTP.SetTimeouts 4000, 4000, 5000, 90000 obj
HTTP.SetRequestHeader "Content-Type", "text/xml" obj
HTTP.Send (strXML) ,,submits the string created by the BuildMessage function
The following is an example of how to retrieve the response string from PAYware Connect using Visual Basic and Microsoft WinHTTP Services version 5.1 (winhttp.dll)
If objHTTP.Status = 200 Then ' HTTP_STATUS_OK=200
strResponse = objHTTP.ResponseText
Else
strResponse = objHTTP.StatusText
End If
Better use the IWinHttpRequest interface.
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "httprequest.inc"
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
LOCAL objHTTP AS IWinHttpRequest
LOCAL bstrURL AS WSTRING
LOCAL bstrResponse AS WSTRING
LOCAL vXML AS VARIANT
vXML = ... ' --> change me!
' Creates an instance of the HTTP service
objHTTP = NEWCOM "WinHttp.WinHttpRequest.5.1"
IF ISNOTHING(objHTTP) THEN EXIT FUNCTION
' Opens an HTTP connection to an HTTP resource
bstrURL = "https://APIDemo.IPCharge.net/IPCHAPI/RH.aspx obj"
objHTTP.Open "POST", bstrURL
' Sends an HTTP request to the HTTP server
objHTTP.SetTimeouts 4000, 4000, 5000, 90000
objHTTP.SetRequestHeader "Content-Type", "text/xml"
objHTTP.Send(vXML)
IF objHTTP.Status = 200 THEN ' HTTP_STATUS_OK=200
bstrResponse = objHTTP.ResponseText
ELSE
bstrResponse = objHTTP.StatusText
END IF
? bstrResponse
END FUNCTION
I tried the program after adding some logic to setup the variables with the correct values and it returns "Bad Request". If i purposely put in the wrong URL I get "Not Found".
So I believe I am getting to the server, not sure what is causing "Bad Request" to return?
The status is coming back as 200.
Any ideas what I should try next?
Turns out the Bad Request was caused by some problem with IWINHTTP according to the folks at VeriFone. I switched to MSXML and the following code worked fine.
FUNCTION PAYWareTransmit(XMLString As String, URL As String) As STRING
If Debug Then Txt.Print FuncName$
LOCAL objHTTP AS IXMLHTTPRequest
LOCAL bstrURL AS WSTRING
LOCAL bstrResponse AS WSTRING
LOCAL vXML AS VARIANT
vXML = XMLString
? XMLString
objHTTP = NEWCOM "Msxml2.XMLHTTP.6.0"
IF ISNOTHING(objHTTP) THEN
? "NEWCOM Msxml2.XMLHTTP.6.0 FAILED"
EXIT FUNCTION
End IF
' Opens an HTTP connection to an HTTP resource
bstrURL = URL
? URL
objHTTP.Open "POST", bstrURL
' Sends an HTTP request to the HTTP server
objHTTP.SetRequestHeader "Content-Type", "text/xml"
objHTTP.Send(vXML)
IF objHTTP.Status = 200 THEN ' HTTP_STATUS_OK=200
bstrResponse = objHTTP.ResponseText + "<>" + STr$(objHTTP.Status) + "<>" + objHTTP.StatusText
? bstrResponse
ELSE
bstrResponse = objHTTP.ResponseText + "<>" + STr$(objHTTP.Status) + "<>" + objHTTP.StatusText
? bstrResponse
END IF
FUNCTION = bstrResponse
END FUNCTION