Can someone post an example (or two) of how you would send XML via an HTTPS Post, either using http_post_page2() or HTTP_POST. This needs to take place from an Alpha web app.
Can someone post an example (or two) of how you would send XML via an HTTPS Post, either using http_post_page2() or HTTP_POST. This needs to take place from an Alpha web app.
Steve Wood
Join the ALPHA DEVELOPERS NETWORK
There is no Cloud. It's just someone else's computer.
Web - Mobile - Hosting - Products - Frameworks - Developer Resources
AlphaToGo | IADN (100% Alpha Anywhere Websites)
http_post_page2() uses a Microsoft ActiveX control that is not server-safe. Kevin Tucker posted a recent thread where he has the code to use Microsoft's server-safe ActiveX control.
You can't use http_post() directly because of the same issue that Kevin originally posted about - it uses the application/x-www-form-urlencoded content type. However you can use the lower-level http_fetch() and set the content type as desired:
Also, the documentation for http_fetch says you cannot use SSL. This is not quite correct, as with Version 8 Enterprise, you can use SSL if needed.Code:dim req as p dim resp as p req.host = "<your server>" req.page = "<your page>" req.method = "POST" req.body = "<your XML here>" req.header = "Content-Type: text/xml" resp = http_fetch(req)
Lenny Forziati
Vice President, Internet Products and Technical Services
Alpha Software Corporation
Thank you Lenny,
1. req.page = <Page> means what?
2. Enterprise Appliciation Server right, not the client Alpha software.
3. Also, is it possible for me to just skip any xbasic function and use this format on an A5W page to send.
<form action="<mypage>" method=post>
<input type=hidden name="Lname" value = "Wood"
etc.
Steve Wood
Join the ALPHA DEVELOPERS NETWORK
There is no Cloud. It's just someone else's computer.
Web - Mobile - Hosting - Products - Frameworks - Developer Resources
AlphaToGo | IADN (100% Alpha Anywhere Websites)
If your URL was http://www.alphatogo.com/customerapp/xmlupload.a5w, the page would be /customerapp/xmlupload.a5w.
It's whatever is running the code. So if this is going in an A5W page, you need an Enterprise Application Server to make an SSL request.
This would send a POST request to the target page, but most browsers (all that I have tested with in the past) will assemble a POST body with URL encoded name-value pairs, not an XML document.
To have the client do all the work without your server as a middle-man, you could use AJAX techniques (essentially Kevin's code, but translated to JavaScript) to send the POST.
Lenny Forziati
Vice President, Internet Products and Technical Services
Alpha Software Corporation
Great - now, so how do I take the XML response that comes from the server and parse the contents? I know its not a readable string. I have tried all of the scripts below, and no value is returned. But I conclude this is because the response is XML, and my attempt to capture as a string is not valid for "response".
bdy = "... my XML here ..."
url = "https://ssl.selectpayment.com/rtg/XMLGateway.aspx"
dim cc as c
cc = http_post_page2(ur,bdy,.t.)
?"response= " + cc
---------------------------------------------------------------
bdy = "... my XML here ..."
dim req as p
dim resp as p
req.host = "https://ssl.selectpayment.com"
req.page = "/rtg/XMLGateway.aspx"
req.method = "POST"
req.body = bdy
req.header = "Content-Type: text/xml"
resp = http_fetch(req)
?"response= " + resp.body
---------------------------------------------------------------
bdy = "... my XML here ..."
dim url as c
url = "https://ssl.selectpayment.com/rtg/XMLGateway.aspx"
obj = ole.create("Msxml2.SERVERXMLHTTP")
obj.setoption(2,13056) 'ignore SSL errors obj.open("POST", url, .f.) obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
obj.send(bdy)
?"response= " + obj.responseText
-------------------------
Steve Wood
Join the ALPHA DEVELOPERS NETWORK
There is no Cloud. It's just someone else's computer.
Web - Mobile - Hosting - Products - Frameworks - Developer Resources
AlphaToGo | IADN (100% Alpha Anywhere Websites)
I am very frustrated with this. I now believe that XML response IS just a text string and I should be able to parse with normal tools. What is happening is that http_post_page2() does not work with HTTPS. It fails with a null response every time. (This is acknowledged in another post, see below).
http_post_page2() DOES work just fine in an Interactive Window for HTTPS, just not from an A5W page. Lenny explains it in another post, but that post has no conclusive results.
And from my testing (which I know is almost always flawed :o until something or someone hits me over the head)... from my testing none of the scripts in my previous post do any better than the naked http_post_pages2() function. None of them return a string from the website if my target is a secure site with HTTPS.
Steve Wood
Join the ALPHA DEVELOPERS NETWORK
There is no Cloud. It's just someone else's computer.
Web - Mobile - Hosting - Products - Frameworks - Developer Resources
AlphaToGo | IADN (100% Alpha Anywhere Websites)
Resolved.
I wish I could find some difference between what I 'came up with' after hours of search and Lenny's code below (to support my 'frustration'), but they are the same.
For those interested in a real life script that calls out to a payment gateway and then returns xml, see below. The variables at the top of the script would be set by a Dialog component, and the line "if eval_valid("PayBill") refers to the Dialog's Submit button (or AdvancedButton).
The last line, ?obj.responseText would be used to store the response in a variable, then values parsed out using normal string functions.
All the transaction values are fake.
-----------------------
Code:<%a5 dim t_gatewayurl as c = "https://ssl.selectpayment.com/rtg/XMLGateway.aspx" dim t_inv as c dim t_storeid as c = "164" dim t_storekey as c = "LrTcbvU5mLo1EgbVVEZ+TW4ETThn" dim t_reqid as c = "req123" dim t_merchantid as c = "1060" dim t_location as c = "1060" dim t_transid as c = "FAKE2" dim t_description as c = "Payment request by Check" dim t_effdate as c = "2007-01-01" dim t_amount as c = "100.00" dim t_nameonacct as c = "Steve Wood" dim t_checkacct as c = "123" dim t_checkrtn as c = "111900659" dim t_paytype as c = "Checking" 'if eval_valid("PayBill") req = "<?xml version='1.0' encoding='utf-8' ?>" + crlf() + \ "<requests xmlns='http://www.selectpayment.com/RTGRequest.xsd'>" + crlf() + \ " <credentials>" + crlf() + \ " <storeID>"+t_storeid+"</storeID>" + crlf() + \ " <storeKey>"+t_storekey+"</storeKey>" + crlf() + \ " </credentials>" + crlf() + \ " <auth requestID='"+t_reqid+"' merchantID='"+t_merchantid+"' locationID='"+t_location+"' transID='"+t_transid+"' description='"+t_description+"'>" + crlf() + \ " <check origin='Internet'>" + crlf() + \ " <amount>"+t_amount+"</amount>" + crlf() + \ " <bankBillTo>" + crlf() + \ " <nameOnAccount>"+t_nameonacct+"</nameOnAccount>" + crlf() + \ " <bankInfo accountType='"+t_paytype+"'>" + crlf() + \ " <account>"+t_checkacct+"</account>" + crlf() + \ " <rtn>"+t_checkrtn+"</rtn>" + crlf() + \ " </bankInfo>" + crlf() + \ " </bankBillTo>" + crlf() + \ " <effectiveDate>"+t_effdate+"</effectiveDate>" + crlf() + \ " </check>" + crlf() + \ " </auth>" + crlf() + \ "</requests>" dim url as c dim body as c url = t_gatewayurl obj = ole.create("Msxml2.SERVERXMLHTTP") obj.setoption(2,13056) 'ignore SSL errors obj.open("POST", url, .f.) obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") obj.send(req) ?obj.responseText %>
Last edited by Steve Wood; 10-20-2007 at 11:38 PM.
Steve Wood
Join the ALPHA DEVELOPERS NETWORK
There is no Cloud. It's just someone else's computer.
Web - Mobile - Hosting - Products - Frameworks - Developer Resources
AlphaToGo | IADN (100% Alpha Anywhere Websites)
http_fetch
As long as you have an enterprise license, you can use http_fetch(). The problem with your test is that .host should only be a hostname and you use the .ssl_on property to use HTTPS:
SERVERXMLHTTPCode:Dim bdy as c = "test" dim req as p dim resp as p req.host = "ssl.selectpayment.com" req.ssl_on = .t. req.ssl_ValidateCert = .f. req.page = "/rtg/XMLGateway.aspx" req.method = "POST" req.body = bdy req.header = "Content-Type: text/xml" resp = http_fetch(req) ?"body: " + resp.body = body: <?xml version="1.0" encoding="utf-8"?> <responses error="true" resultCode="Error_Invalid_Format" responseMessage="The data at the root level is invalid. Line 1, position 1." />
Your example works for me. One potential problem however is that you are setting the content type to specify a urlencoded body, which you send in this test but you would not be sending if you are POSTing an XML document
Code:dim url as c dim body as c url = "https://ssl.selectpayment.com/rtg/XMLGateway.aspx" body = "test=foobar" obj = ole.create("Msxml2.SERVERXMLHTTP") obj.setoption(2,13056) 'ignore SSL errors obj.open("POST", url, .f.) obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") obj.send(body) ?"body:" + obj.responseText = body:<?xml version="1.0" encoding="utf-8"?> <responses error="true" resultCode="Error_Invalid_Format" responseMessage="The data at the root level is invalid. Line 1, position 1." />
http_post_page2()
This is not server safe - it will hang your server eventually and should be avoided for your particular use in an A5W page. But it will work OK from a desktop script:
Code:url = "https://ssl.selectpayment.com/rtg/XMLGateway.aspx" dim cc as c cc = http_post_page2(url,bdy) ?"body: " + cc = body: <?xml version="1.0" encoding="utf-8"?> <responses error="true" resultCode="Error_Invalid_Format" responseMessage="The data at the root level is invalid. Line 1, position 1." />
Lenny Forziati
Vice President, Internet Products and Technical Services
Alpha Software Corporation
Great. So the one I finally got working, is the one I should avoid!
I will try to document this for other's use after I am done. The Help is not detailed enough in this area to point out what to do.
Please for now though - just tell me which method I should use in this case so I can focus on that one.
Specs:
- Sending XML, expecting XML response to the same page that sent the request.
- Have the Enterprise Alpha server.
- Transmission must be over SSL.
- Need to test from a desktop connection, then migrate to the server for test/final.
- My desktop does not have SSL, so my test needs to work with/without SSL on the testing machine.
Steve Wood
Join the ALPHA DEVELOPERS NETWORK
There is no Cloud. It's just someone else's computer.
Web - Mobile - Hosting - Products - Frameworks - Developer Resources
AlphaToGo | IADN (100% Alpha Anywhere Websites)
The one you got to work is fine. http_post_page2() is not server safe because it uses XMLHTTP instead of SERVERXMLHTTP that you are using.
You can either stick with what you are using or use http_fetch(). I prefer http_fetch() because it gives more flexibility. But your SERVERXMLHTTP has a responseXML property which will be a parsed XML document if the server sends back proper XML. You can work with that, if you know how, instead of using Xbasic to manually parse the response from http_fetch()
Lenny Forziati
Vice President, Internet Products and Technical Services
Alpha Software Corporation
Update.
I have stopped using some code that is referenced a couple posts down in this thread for web services. The code block starts with ole.create("Msxml2.SERVERXMLHTTP").
It was causing my WAS to lock up frequently. It would lock up about three minutes AFTER the web services were completed. I never could figure out exactly why it locked up, it just did. The only error I could see was in the Xbasic Error Stack log and said something like "could not start the server".
I replaced it with the following, where "url" is the full URL to the web services, and req is my HTTP POST request as a string. An example value for url is "https://www.paypal.com/cgi-bin/webscr".
dim pm as p
dim pm.host as c = a5_split_url(url).protocol + "//" + a5_split_url(url).server
dim pm.page as c = a5_split_url(url).page
dim pm.port as n = 443
dim pm.method as c = "post"
dim pm.ssl_on as l = .t.
dim pm.body as c = req
resp = http_fetch(pm)
Steve Wood
Join the ALPHA DEVELOPERS NETWORK
There is no Cloud. It's just someone else's computer.
Web - Mobile - Hosting - Products - Frameworks - Developer Resources
AlphaToGo | IADN (100% Alpha Anywhere Websites)
Bookmarks