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

Re: Fw: RPG calling a web service / HTTP 1.1 500 InternalServer Error, here is the attached code



Michael I remember getting that same message a few weeks ago when I first started using Scotts tools.
I'm afraid I don't remember exactly what the deal was...
What you are trying to do sounds very similar to what I've been doing.... (I think?) so I've attached the code that is working very well for me. I hope this helps...
One thing, you need HTTPAPI  1.11 pre release to use Scotts encoding subprocedures.
Otherwise you have to encode your XML manually or I wrote a procedure to do it before I knew about 1.11
This code sends the vedors response to the IFS and even displays it on the screen, makes it real easy for testing!
good luck
Eric

>>> miketinternet@xxxxxxxxx 07/15/05 9:11 AM >>>
Sender: Michael Tierney <miketinternet@xxxxxxxxx>

I didn't see an example that is similar to what I
am trying to do, RPG sending a request and
looking for a simple sucess or failure.  The best
I could tell was the UPS example.

In any event, there is a need with the RPG guys I
deal with to send XML strings via HTTP to web
services and get a reply.

On the code I sent, the error states something
about the program expecting a character input
field with a maximum length of 52a. Is the
conflict because non Iseries is Varchar and
Iseries is fixed character length ?

--- Scott Klement <sk@xxxxxxxxxxxxxxxx> wrote:

> Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>
>
>
> > Am I heading in the correct direction ? I am
> > trying to send an HTTP string out to a web
> > service from RPG and get back a reply of
> success
> > or failure. I would love to use an XML parser
> of
> > some sort for the data and tag it to the end
> of
> > the HTML string.
>
> Yes, I think you're headed in the right
> direction. Your code looks good to
> me, but apparently theres some detail that the
> server isn't happy with. If
> you can get all of the details right, it shoudl
> work.
>
> > If there is a more simple example you have I
> will
> > definitely try it.
>
> Hmmm..  I thought the EXAMPLE source members
> were pretty simple...
>
>
-----------------------------------------------------------------------
> This is the FTPAPI mailing list.  To unsubsribe
> from the list send mail
> to majordomo@xxxxxxxxxxxxx with the body:
> unsubscribe ftpapi mymailaddr
>
-----------------------------------------------------------------------
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------
     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')

     D/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

      ** http_url_encoder_addvar() became available with
      ** HTTPAPI 1.11 pre release

      ** What I'm going to send to my vendor - before encoding...

      **    http://www.myvendor.com/API/mailing_list.html
      **    type=list
      **    activity=add
      **    input=<?xml version="1.0" encoding="iso-8859-1"?>
      **          <DATASET>'
      **            <SITE_ID>12345</SITE_ID>'
      **            <DATA type="name">EJ Mailing List XML</DATA>
      **            <DATA type="type">Mailing List XML</DATA>
      **          </DATASET>


      ** What my vendor is going to send back to me

      **    <?xml version="1.0" encoding="iso-8859-1"?>
      **    <DATASET>                                                  ATASET>
      **      <TYPE>success</TYPE>                                     ATASET>
      **      <DATA type="mlid">15</DATA>                              ATASET>
      **    </DATASET>                                                 ATASET>

      ** To do URL encoding data, you must create a "URL Encoder"
      ** and then use it to encode each variable of the web form
      ** as follows:

      /free

        ApiTyp = 'list';

        ApiAct = 'add';

        ApiInp = '<?xml version="1.0" encoding="iso-8859-1"?>'  + CRLF +
                 '<DATASET>'                                    + CRLF +
                 '<SITE_ID>12345</SITE_ID>'                     + CRLF +
                 '<DATA type="name">EJ Mailing List XML</DATA>' + CRLF +
                 '<DATA type="type">Mailing List XML</DATA>'    + 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 );

        rc = http_url_post( 'http://www.myvendor.com/API/mailing_list.html  '
                          : myPointer
                          : dataSize
                          : '/tmp/testpost.html'
                          : HTTP_TIMEOUT
                          : HTTP_USERAGENT
                          : 'application/x-www-form-urlencoded');


        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;

      /end-free