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

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



Hi Scott, Hi everybody,

 

thank you for the fast answer.

 

The api is a post api to request simple orders, item by item (item, quantity, shipping adress, ...), and receive the order number in the response if ok,

or an error code if not ok (unknown item, etc...).

 

SSL cipher suites are matching on both sides.

 

With the same specs than in my rpg code, the request works fine on Postman.  

Here are the main Postman screens (Authorization, Headers and Body).

 

 

postman_auth.jpg

 

postman_headers.jpg

 

postman_body.jpg

 

 

As a test, I just tried to send the request  with Postman, after have disabled one of parameter,

and then the request fails like from my AS/400 request, on the same error message on the the first parameter : isbn is missing.

 

 

So I put all the parameters in the input datas in my rpg.  But it still fails with the same error...

 

 

I TRIED LIKE THAT :

 

    ApiInp =                             

 

    'isbn=9782764401859&'         

  + 'quantity=1&'                 

  + 'society=SOCADIS&'            

  + 'address=420,+rue+stinson&'   

  + 'zip=H4N+3L7&'                

  + 'city=Ville+Saint-Laurent&'   

  + 'country=Canada&'             

  + 'num_cmd=cmd00100&'           

  + 'group_cmd=20171107&'         

  + 'id_client=00255';            

   

AND ALSO LIKE THAT :          

                             

   'isbn=9782764401859' + @CRLF          

 + 'quantity=1'+ @CRLF                   

 + 'society=SOCADIS' + @CRLF             

 + 'address=420,+rue+stinson' + @CRLF     

 + 'zip=H4N+3L7' + @CRLF                 

 + 'city=Ville+Saint-Laurent'+ @CRLF     

 + 'country=Canada' + @CRLF              

 + 'num_cmd=cmd00100' + @CRLF            

 + 'group_cmd=20171107' + @CRLF          

 + 'id_client=00255';                     

 

 

 

The problem really seems to come from the way the input datas are formated in my rpg code...

           

                       

Thank you for your apreciated help.

 

Regards.

Chris

 

 

 

 

 

De : ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] De la part de Scott Klement
Envoyé : 7 novembre 2017 03:36
À : FTPAPI/HTTPAPI mailing list
Objet : Re: [Ftpapi] data set form problem http_url_post with enctype x-www-form-urlencoded

 

Hi Christophe,

Although I understand your sample code and what it does, I am not familiar with the web service you are trying to call.   I cannot tell you how to change your code to match the specs for the web service if I know nothing about it.

Please tell us these specs so that we know what you need HTTPAPI to do.   With this information, we can advise how to code it.

-SK

 

On 11/6/17 4:15 PM, Christophe Welker wrote:

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

 

 

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

 

 



 

Attachment: postman_auth.jpg
Description: postman_auth.jpg

Attachment: postman_headers.jpg
Description: postman_headers.jpg

Attachment: postman_body.jpg
Description: postman_body.jpg

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