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

[Ftpapi] data set form problem http_url_post with enctype x-www-form-urlencoded



Hi all,

 

 

 

Usualy I always send xml files with http_url_post,

this time I have to send  x-www-form-urlencoded type for the first time.

 

But the request always fails ("first parameter missing"), and the returned HTTP_ERROR code is always zero.

 

 

Below is my code that I adapted from this example from Scott, found in this FTPAPI mailing list archive :

http://scottklement.com/archives/ftpapi/200507/msg00044.html

 

 

Does the problem come from the way to form the input data ?

I tried :

- Param1=Value1&Param2=Value2       

- XML format

- Param1= Value1 CLRF Param1= Value1

 

 

Or is this an authentification problem due to HTTPS ?

In debug all the authentifications steps seem to run well

(1st call to connect,

get a -1 with http_error set to HTTP_NDAUTH,

http_getauth to get the digest mode and realm name,

http_setauth with user/pwd)

 

 

 

Thank you very much for your help.

Regards.

Chris

 

 

 

 

 

      *********************************************************

 

     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')

 

      /COPY LIBHTTP/QRPGLESRC,HTTPAPI_H

 

     D cmd             pr                  extpgm('QCMDEXC')

     D  command                     200A   const

     D  length                       15P 5 const

 

     D CRLF            C                   CONST(x'0D25')

     D rc              s             10I 0

     D msg             s             52A

 

     D EncData         s                   like(HTTP_URL_ENCODER)

     D ApiTyp          s            128A   varying

     D ApiAct          s            128A   varying

     D ApiInp          s           1024A   varying

     D myPointer       s               *

     D dataSize        s             10I 0

 

     D@WS_USR          C                   CONST('socadis')

     D@WS_PWD          C                   CONST('socadis20170307')

 

      * Variables de travail XML

     D$URL             S            200A   VARYING

     D$XML_FILE        S            200A   VARYING

     D$POS             S              3S 0

     D $location       S            100A

     D ERR             S             10I 0

     D basic           S              1N

     D digest          S              1N

     D realm           S            124A

     D data            S           2000A   VARYING

     DY                S              3  0 INZ(*ZEROS)

     D@CRLF            C                   CONST(X'0D25')

 

 

           /free

 

                   ApiTyp = 'list';

 

                   ApiAct = 'add';

 

 

 

                   ApiInp =

 

                  'isbn=9782764401859&quantity=1';

 

             //   'isbn=9782764401859' + @CRLF

             //    + 'quantity=1';

 

 

             //    '<?xml version="1.0" encoding="iso-8859-1"?>'  + CRLF +

             //    '<DATASET>'                                    + CRLF +

             //    '<isbn>9782764401859</isbn>'                   + CRLF +

             //    '<quantity>1</quantity>'                       + CRLF +

             //    '</DATASET>'                                   + CRLF ;

 

 

 

                   EncData = http_url_encoder_new;

                   http_url_encoder_addvar( EncData

                                                  : 'type'

                                                  : %addr(ApiTyp)+2

                                                  :  %len(ApiTyp) );

 

                   http_url_encoder_addvar( EncData

                                                  : 'activity'

                                                  : %addr(ApiAct)+2

                                                  : %len(ApiAct) );

 

                   http_url_encoder_addvar( EncData

                                                  : 'input'

                                                  : %addr(ApiInp)+2

                                                  : %len(ApiInp) );

 

                   http_url_encoder_getptr( EncData

                                                  : myPointer

                                                  : dataSize );

 

           // Définir l'adresse du service web pour le POST

              $URL = '' +

                'CmdLight/format/xml';

 

                   rc = http_url_post(%TRIM($URL)

                                             : myPointer

                                             : dataSize

                                             : '/tmp/testpost.html'

                                             : HTTP_TIMEOUT

                                             : HTTP_USERAGENT

                                             :

                   'application/x-www-form-urlencoded');

 

              IF (RC <> 1);

 

                  http_error(ERR);

                  IF ERR = HTTP_NDAUTH;  // Authentification n‚cessaire

                     EXSR R21000;

                     Y = 0;

                     DOU RC = 201 OR Y = 60;

                          rc = http_url_post(%TRIM($URL)

                                             : myPointer

                                             : dataSize

                                             : '/tmp/testpost.html'

                                             : HTTP_TIMEOUT

                                             : HTTP_USERAGENT

                                             :

                              'application/x-www-form-urlencoded');

                         http_error(ERR);

                         Y += 1;

                     ENDDO;

                  ENDIF;

              ENDIF;

 

 

              cmd('DSPF ''/tmp/testpost.html''': 200);

 

                  if  rc <> 1;

                      msg = http_error;

                      dsply msg;

                  else;

                      cmd('DSPF ''/tmp/testpost.html''': 200);

                  endif;

 

            // When done, make sure you call this function to free up

            // the memory that the URL Encoder used.

 

             http_url_encoder_free(EncData);

 

                     *inlr = *on;

 

        //------------------------------------------//

        //                                          //

        //             AUTHENTIFICATION             //

        //                                          //

        //------------------------------------------//

 

        BEGSR R21000;

 

            RC = http_getauth(basic: digest: realm);

            IF (RC = 0);

               IF digest;

                  http_setauth(HTTP_AUTH_MD5_DIGEST: @WS_USR: @WS_PWD);

               ELSE;

                  http_setauth(HTTP_AUTH_BASIC: @WS_USR: @WS_PWD);

               ENDIF;

            ENDIF;

 

        ENDSR;

 

 

 

           /end-free

 

 

      *********************************************************

 

 

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