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

Re: HTTPS POST - modifying Example 5 - Help needed



hi Sarvapriya,

You've forgotten to set the content-type to 
application/x-www-form-urlencoded.  You did this in the Java example, 
but not in the RPG one.

The content-type is set as the 8th parameter to http_url_post_raw(). 
Take a look at the parameter descriptions in HTTPAPI_H for details.


On 6/1/2010 11:20 AM, Sarvapriya_Tripathi@xxxxxxxxx wrote:
>
>     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("[1]https://secure.bluepay.com/interfaces/bp10emu";);
>                     String params =
>     "TAMPER_PROOF_SEAL=1234abcd1234abcd1234abcd1234abcd&MERCHANT=123456789
>     012&MODE=TEST&TRANSACTION_TYPE=SALE&AMOUNT=100&REBILLING=0&REB_FIRST_D
>     ATE=&REB_EXPR=&REB_CYCLES=&REB_AMOUNT=&AMOUNT_TAX=&AMOUNT_TIP=&ORDER_I
>     D=&INVOICE_ID=&CUSTOM_ID=&CC_NUM=4111111111111111&CC_EXPIRES=0614&CVCC
>     VV2=123&NAME=Test+Transaction&ADDR1=123+Foo+Street&ADDR2=&AVS_ALLOWED=
>     &CVV2_ALLOWED=&AUTOCAP=0&CITY=Bluepay+Town&STATE=IL&ZIPCODE=60653&COMM
>     ENT=&PHONE=&EMAIL=&RRNO=&MISSING_URL=nu&APPROVED_URL=nu&DECLINED_URL=n
>     u&";
>                     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=_&ORDE
>     R_ID=10
>
>     0043659302&CARD_EXPIRE=0614&Result=DECLINED&RRNO=100043659302&CVV2=_&P
>     AYMENT_
>       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 noti
> fy the sender immediately by return
> email, and destroy this communication andall copies of it, including all attach
> ments. 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 ind
> irectly therefrom.
>
> References
>
>     1. https://secure.bluepay.com/interfaces/bp10emu
>
>
>
>
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list.  To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------