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

Re: [Ftpapi] [EXTERNAL] Re: SetError() #2: Host name look up failed



David,

Just for kicks, I refactored your example program to modernize it a little bit.   I've attached two newer versions

1- keeps your hybrid of fixed/free, but uses http_req().  Notice how much shorter, simpler, cleaner, the code is.

2- Converts the whole thing to free format.

Thought you might find them interesting.

--
Scott Klement
sk@xxxxxxxxxxxxxxxx

On 12/2/2020 4:43 PM, Scott Klement wrote:

David,

I see the problem, now.   Sorry, I did not look closely enough at your code.  You are not passing the correct parameters to http_url_post_raw.


**free

//  Generic HTTP POST STMF program using Scott Klement's LIBHTTP 1.23
//  uses the "raw" versio of http_url_post(). The advantage is
//  that data is received directly into a variable in the program
//  instead of writing it to the IFS.
//
// * Program accepts 6 Parms
// *  1. Standard 2E 7 byte return code. Blank = Ran Ok, Non-Blank is an error
// *  2. Output error message 52 bytes
// *  3. Destination URL     512 bytes
// *  4. Content-Type        256 bytes
// *  5. Input  Data       32766 bytes
// *  6. Output Data       32766 bytes
//
// *  Compile Options:
// *  Put LIBHTTP at the top of the *LIBL
// *
// *  CRTBNDRPG PGM(W2GEND/WODSAUR0)
// *            SRCFILE(W2SRCD/QRPGLESRC)
// *            DFTACTGRP(*NO)
// *            ACTGRP(*NEW)
// *            DBGVIEW(*SOURCE)
// *            REPLACE(*YES)
// *            TGTRLS(*CURRENT)
// *
// *  TURNOVER:
// *      TEST: Compile once in D and use CSCD option
// *      PROD: CSCD option - DO NOT RECOMPILE!
// --------------------------------------------------------------*
// IMB LIBHTTP copies required to run Post API procedures.
// --------------------------------------------------------------*

ctl-opt DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('HTTPAPI');

 /copy qrpglesrc,httpapi_h

dcl-s rc int(10);
dcl-s msg char(52);
dcl-s retdata varchar(32766:4);

// *ENTRY PLIST:
dcl-pi *N;
  PR_Return_Code char(7);
  PR_Error_Msg   char(52);
  PR_Destination char(512);
  PR_Content_Typ char(256);
  PR_Send        char(32766);
  PR_Return      char(32766);
end-pi;

*inlr = *on;
http_debug(*ON);
https_init(*blanks: *ON: *ON: *ON: *ON: *ON);

rc = http_req( 'POST'
             : %trim(PR_Destination)
             : *omit
             : retdata
             : *omit
             : %trimr(PR_Send)
             : %trim(PR_Content_Typ) );

if rc <> 1;
   msg = http_error;
   dsply msg;
   return;
endif;

if %len(retdata) > 1;
   PR_Return = retdata;
endif;

return;
 
      * Generic HTTP POST STMF program using Scott Klement's LIBHTTP 1.23
      * uses the "raw" versio of http_url_post(). The advantage is
      * that data is received directly into a variable in the program
      * instead of writing it to the IFS.
      *
      ** Program accepts 6 Parms
      **  1. Standard 2E 7 byte return code. Blank = Ran Ok, Non-Blank is an error
      **  2. Output error message 52 bytes
      **  3. Destination URL     512 bytes
      **  4. Content-Type        256 bytes
      **  5. Input  Data       32766 bytes
      **  6. Output Data       32766 bytes

      **  Compile Options:
      **  Put LIBHTTP at the top of the *LIBL
      **
      **  CRTBNDRPG PGM(W2GEND/WODSAUR0)
      **            SRCFILE(W2SRCD/QRPGLESRC)
      **            DFTACTGRP(*NO)
      **            ACTGRP(*NEW)
      **            DBGVIEW(*SOURCE)
      **            REPLACE(*YES)
      **            TGTRLS(*CURRENT)
      **
      **  TURNOVER:
      **      TEST: Compile once in D and use CSCD option
      **      PROD: CSCD option - DO NOT RECOMPILE!
      *--------------------------------------------------------------*
      * IMB LIBHTTP copies required to run Post API procedures.
      *--------------------------------------------------------------*
     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('HTTPAPI')

     D/copy qrpglesrc,httpapi_h

     D rc              s             10I 0
     D msg             s             52A
     D retdata         S          32766A   varying(4)
      *
     C     *ENTRY        PLIST
     C                   PARM                    PR_Return_Code    7
     C                   PARM                    PR_Error_Msg     52
     C                   PARM                    PR_Destination  512
     C                   PARM                    PR_Content_Typ  256
     C                   PARM                    PR_Send       32766
     C                   PARM                    PR_Return     32766
      /free
          *inlr = '1';
          http_debug(*ON);
          https_init(*blanks: *ON: *ON: *ON: *ON: *ON);

          rc = http_req( 'POST'
                       : %trim(PR_Destination)
                       : *omit
                       : retdata
                       : *omit
                       : %trimr(PR_Send)
                       : %trim(PR_Content_Typ) );

          if rc <> 1;
             msg = http_error;
             dsply msg;
             return;
          endif;

          if %len(retdata) > 1;
             PR_Return = retdata;
          endif;

          return;
       /end-free
 
-- 
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi