[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: HTTPS POST - modifying Example 5 - Help needed



Hi,

Welcome to HTTPAPI. It is good to see you trying some new things on the IBMi. Since you have it working in Java, any reason you'd like to re-write it in HTTPAPI?

Scott gave you a quick answer that will surely help (he knows this stuff very well). I'll give you another.

My suggestion...Download the latest Beta (http://www.scottklement.com/httpapi/beta/). Save the old example programs as they sometimes come in handy. The new EXAMPLE4 is the one you should look at. There is a new function available that makes post work more like a webpage (which is what your page appears to be). Scott also re-wrote the examples with pretty good explanations.

EXAMPLE4 will load the parameters into the "form" and post the results of that form -- getting the response into a file. Turn on debugging (see the beta page for instructions) and you will have the information (in the debug file or the downloaded data file) you need to figure out if your process is working.

It appears you have to parse the head section of the returned page for the answer to your post. You will want to work with HTTP_POINT_PARSE_HEADER when you get to that point. Running the BETA code, I don't have the "old" EXAMPLE12 - but there is a reference to that example showing how to use the routine. This message (http://www.scottklement.com/archives/ftpapi/200601/msg00018.html ) also has a small section of code in it that might lend a hand.

Good luck. Keep us informed of progress.
Mike Krebs

> -----Original Message-----
> From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-
> bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> Sarvapriya_Tripathi@xxxxxxxxx
> Sent: Tuesday, June 01, 2010 11:20 AM
> To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
> Subject: HTTPS POST - modifying Example 5 - Help needed
> 
> Hi,
> 
> I am new to the list and HTTPAPI. I am trying to modify example 5 to do
> a
> HTTPS POST to a site. I have the following working Java program that I
> am
> trying to adapt (sorry if the code does not render correctly in the
> email,
> also, I have changed the Tamper Proof Seal and Merchant ID for privacy,
> otherwise, rest of the code is unchanged) -
> 
> package com.bluepay;
> 
> import java.io.OutputStream;
> import java.io.OutputStreamWriter;
> import java.net.URL;
> 
> import javax.net.ssl.HttpsURLConnection;
> 
> /**
>  *
>  */
> public class TestWebLink
> {
>   public static void main(String[] args)
>   {
>     try
>     {
>                 URL myURL = null;
>                 myURL = new java.net.URL("
> https://secure.bluepay.com/interfaces/bp10emu";);
> 
>                 String params =
> "TAMPER_PROOF_SEAL=1234abcd1234abcd1234abcd1234abcd&MERCHANT=1234567890
> 12&MODE=TEST&TRANSACTION_TYPE=SALE&AMOUNT=100&REBILLING=0&REB_FIRST_DAT
> E=&REB_EXPR=&REB_CYCLES=&REB_AMOUNT=&AMOUNT_TAX=&AMOUNT_TIP=&ORDER_ID=&
> INVOICE_ID=&CUSTOM_ID=&CC_NUM=4111111111111111&CC_EXPIRES=0614&CVCCVV2=
> 123&NAME=Test+Transaction&ADDR1=123+Foo+Street&ADDR2=&AVS_ALLOWED=&CVV2
> _ALLOWED=&AUTOCAP=0&CITY=Bluepay+Town&STATE=IL&ZIPCODE=60653&COMMENT=&P
> HONE=&EMAIL=&RRNO=&MISSING_URL=nu&APPROVED_URL=nu&DECLINED_URL=nu&"
> ;
>                 String paramsLen = String.valueOf(params.length());
>                 HttpsURLConnection hcon = null;
>                 hcon = (HttpsURLConnection) myURL.openConnection();
> 
>                 hcon.setAllowUserInteraction(false);
>                 hcon.setUseCaches(false);
>                 hcon.setDoInput(true);
>                 hcon.setDoOutput(true);
>                 hcon.setInstanceFollowRedirects(false);
>                 hcon.setRequestMethod("POST");
>                 hcon.setRequestProperty("Content-Type",
> "application/x-www-form-urlencoded");
>                 hcon.setRequestProperty("Content-Length", paramsLen);
> 
>                 OutputStream os = hcon.getOutputStream();
>                 OutputStreamWriter osw = new OutputStreamWriter(os);
>                 // send request
>                 osw.write(params);
>                 osw.flush();
>                 osw.close();
> 
>                 int rescode = hcon.getResponseCode();
>                 if (rescode != 302) {
>                         // Response other than 302 not expected -
> return
>                         return;
>                 }
> 
>                 // Response returned is in Location Header
>                 String loc = hcon.getHeaderField("Location");
>                 System.out.println("Raw Location Data: " + loc);
>     }
>     catch (Exception ex)
>     {
>       System.out.println("Exception: " + ex.toString());
>       System.exit(1);
>     }
> 
>   }
> }
> 
> The above, when run on my i5 (V5R4), gives the following response -
> 
> > java com.bluepay.TestWebLink
>   Raw Location Data:
> nu?INVOICE_ID=123456789012&BANK_NAME=&PAYMENT_ACCOUNT=xxxx
> 
> xxxxxxxx1111&AUTH_CODE=&CARD_TYPE=VISA&AMOUNT=100.00&REBID=&AVS=_&ORDER
> _ID=10
> 
> 0043659302&CARD_EXPIRE=0614&Result=DECLINED&RRNO=100043659302&CVV2=_&PA
> YMENT_
>   TYPE=CREDIT&MESSAGE=Declined%20Sale
> 
> 
> I am trying to get the same response using the following RPG code -
> 
>       * Test 1 for Bluepay
>      H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('HTTPAPI')
> 
>      D/copy qrpglesrc,httpapi_h
> 
>      D incoming        PR            10I 0
>      D   descriptor                  10I 0 value
>      D   data                      8192A   options(*varsize)
>      D   datalen                     10I 0 value
> 
>      D rc              s             10I 0
>      D msg             s             52A
>      D CRLF            C                   CONST(x'0d25')
>      D data            S           1024A
>      D retdata         S          32766A
>      D retlen          S             10I 0
>      D nextpos         S             10I 0 inz(1)
> 
>       /free
> 
>        *inlr = *on;
> 
>        data = 'TAMPER_PROOF_SEAL=1234abcd1234abcd1234abcd1234abcd&' +
>               'MERCHANT=123456789012&MODE=TEST&TRANSACTION_TYPE=SALE&'
> +
>         'AMOUNT=100&REBILLING=0&REB_FIRST_DATE=&REB_EXPR=&REB_CYCLES=&'
> +
> 
> 'REB_AMOUNT=&AMOUNT_TAX=&AMOUNT_TIP=&ORDER_ID=&INVOICE_ID=&'
> +
> 
> 'CUSTOM_ID=&CC_NUM=4111111111111111&CC_EXPIRES=0614&CVCCVV2=123&'+
> 
> 'NAME=Test+Transaction&ADDR1=123+Foo+Street&ADDR2=&AVS_ALLOWED=&'+
>               'CVV2_ALLOWED=&AUTOCAP=0&CITY=Bluepay+Town&STATE=IL&' +
> 
> 'ZIPCODE=60653&COMMENT=&PHONE=&EMAIL=&RRNO=&MISSING_URL=nu&'
> +
>               'APPROVED_URL=nu&DECLINED_URL=nu&' + CRLF;
> 
>        rc = http_url_post_raw('https:
> //secure.bluepay.com/interfaces/bp10emu':
>                               %addr(data): %len(%trimr(data)):
>                               1: %paddr('INCOMING'));
>        // http response other than 302 not expected, error...
>        if ((rc <> 1) and (rc <> 302));
>          msg = http_error;
>          dsply  msg;
>          return;
>        endif;
> 
>        // convert the data we just received to EBCDIC
>        if (retlen > 1);
>          http_xlate(retlen: retdata: TO_EBCDIC);
>        endif;
> 
>        return;
> 
>       /end-free
> 
> 
> 
> P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>      P*  this procedure will receive the raw data received from UPS
> 
> P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>      P incoming        B
>      D incoming        PI            10I 0
>      D   descriptor                  10I 0 value
>      D   data                      8192A   options(*varsize)
>      D   datalen                     10I 0 value
> 
>      C* Make sure we don't overflow the string:
>      c                   eval      retlen = (nextpos + datalen) - 1
>      c                   if        retlen > %size(retdata)
>      c                   eval      datalen=datalen-(retlen-
> %size(retdata))
>      c                   endif
> 
>      C* If there is nothing to write, return THAT...
>      c                   if        datalen < 1
>      c                   return    0
>      c                   endif
> 
>      C* Here we add any data sent to the end of our 'retdata' string:
>      c                   eval      %subst(retdata: nextpos) =
>      c                                %subst(data:1:datalen)
>      c                   eval      nextpos = nextpos + datalen
> 
>      c* We always return the amount of data that we wrote.   Note
>      C*  that if http-api sees that we didn't write as much data as
>      C*  it sent us, it'll abort the process with an error message.
>      c                   return    datalen
>      P                 E
> 
> And this is the response that I receive -
> 
> EVAL retdata
> RETDATA =
>           ....5...10...15...20...25...30...35...40...45...50...55...60
>      1   '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><he'
>     61   'ad><title>302 Moved</title></head><body><h1>Moved</h1><p'
>    121   '>The document has moved <a href="/interfaces/wlcatch?Result='
>    181   'MISSING&amp;MESSAGE=Missing%20MERCHANT&amp;Missing=MERCHANT"'
>    241   '>here</a>.</p></body></html>                              '
>    301   '                                                            '
> 
> According to the vendor, this response is sent when the request being
> sent
> to them is not properly URL encoded. What am I doing wrong here
> 
> 
> 
> Thanks and Regds
> 
> The information contained in this electronic communication and any
> accompanying document is confidential, may be
> attorney-client privileged, and is intended only for the use of the
> addressee. It is the property of Ryder System,
> Inc. Unauthorized use, disclosure or copying of this communication, or
> any part of it, is strictly prohibited and
> may be unlawful.  If you have received this communication in error,
> please notify the sender immediately by return
> email, and destroy this communication andall copies of it, including
> all attachments. Electronic communication
> may be susceptible to data corruption, interception and unauthorized
> tampering and Ryder disclaims all liability
> of any kind for such actions or any consequences that may arise
> directly or indirectly therefrom.
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------