Alpha DevCon 2018
Results 1 to 11 of 11

Thread: http_post_page2() or HTTP_POST

  1. #1
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,785

    Default http_post_page2() or HTTP_POST

    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)

  2. #2
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,625

    Default Re: http_post_page2() or HTTP_POST

    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:
    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)
    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.

    Lenny Forziati
    Vice President, Internet Products and Technical Services
    Alpha Software Corporation

  3. #3
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,785

    Default Re: http_post_page2() or HTTP_POST

    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)

  4. #4
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,625

    Default Re: http_post_page2() or HTTP_POST

    Quote Originally Posted by Steve Wood View Post
    Thank you Lenny,

    1. req.page = <Page> means what?
    If your URL was http://www.alphatogo.com/customerapp/xmlupload.a5w, the page would be /customerapp/xmlupload.a5w.


    Quote Originally Posted by Steve Wood View Post
    2. Enterprise Appliciation Server right, not the client Alpha software.
    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.

    Quote Originally Posted by Steve Wood View Post
    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.
    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

  5. #5
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,785

    Default Re: http_post_page2() or HTTP_POST

    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)

  6. #6
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,785

    Default Re: http_post_page2() or HTTP_POST

    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)

  7. #7
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,785

    Default Re: http_post_page2() or HTTP_POST

    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 10: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)

  8. #8
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,625

    Default Re: http_post_page2() or HTTP_POST

    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:
    Code:
    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." />
    SERVERXMLHTTP
    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

  9. #9
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,785

    Default Re: http_post_page2() or HTTP_POST

    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)

  10. #10
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,625

    Default Re: http_post_page2() or HTTP_POST

    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

  11. #11
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,785

    Default Re: http_post_page2() or HTTP_POST

    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)

Similar Threads

  1. Http_Post
    By Walter in forum Alpha Five Version 7
    Replies: 0
    Last Post: 12-04-2006, 10:39 AM
  2. http_post
    By Walter in forum Alpha Five Version 7
    Replies: 4
    Last Post: 10-25-2006, 06:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •