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

Re: FW: Stumped By Simple Task



Hello W,

If your parameters are already URL encoded, it's as simple as doing something like this:

     H DFTACTGRP(*NO) ACTGRP('KLEMENT')
     H BNDDIR('HTTPAPI') OPTION(*SRCSTMT)

      /copy httpapi_h

     D url             s            500a   varying
     D rc              s             10i 0
     D stmf            s           1024a   varying

      /free
       url  = 'https://dmapi.com/user="username"&id="id"&doc="1234";';
       stmf = '/tmp/output.txt';

       rc = http_get( url: stmf );
       if rc <> 1;
          http_crash();
       endif;

       *inlr = *on;


If you need HTTPAPI to URL-encode them for you, then you'll want to ask HTTPAPI to build you a web form, and add each variable to it. The result should look something like this:

     H DFTACTGRP(*NO) ACTGRP('KLEMENT')
     H BNDDIR('HTTPAPI') OPTION(*SRCSTMT)

      /define WEBFORMS
      /copy httpapi_h

     D UserId          s             64a   varying inz('"username"')
     D Id              s             64a   varying inz('"id"')
     D doc             s             10a   varying inz('"1234"')
     D form            s                   like(WEBFORM)
     D url             s            500a   varying
     D rc              s             10i 0
     D stmf            s           1024a   varying

      /free
       // Build a URL-Encoded Form

       form = WEBFORM_open();
       WEBFORM_setVar( form: 'user': %trim(UserId));
       WEBFORM_setVar( form: 'id'  : %trim(Id));
       WEBFORM_setVar( form: 'doc' : %trim(doc));
       url  = 'https://dmapi.com/' + WEBFORM_getData(form);
       WEBFORM_close(form);

       // Send a GET request with form data in the URL:

       stmf = '/tmp/output.txt';
       rc = http_get( url: stmf );
       if rc <> 1;
          http_crash();
       endif;

       *inlr = *on;

Hope that helps.



On 7/1/2012 4:01 PM, w 4038 wrote:
    Hi
    I've used Scott's HTTPAPI tool to get the weather, currency and UPS
    package information to the AS400.  (Thanks Scott for writing the
    articles showing how to do this.)

    In comparison to those examples, I have what seems to be a very simple
    task, but I don't see how the HTTPAPI tool can accomplish it.

    Scott's articles show you how to use WSDL and SOAP to form a web
    request, retrieve the reply and then parse it.  But what if your vendor
    doesn't use WSDL or SOAP?

    Currently, we store documents in the "cloud" on a vendor's site.  In
    order to delete a document, the vendor's instructions show a simple
    request like:
    https://dmapi.com/user="username"&id="id"&doc="1234";

    This returns a session id.  With that session id, you can then delete
    the document by issuing another simple request:
    https://dmapi.com/session=sessionid&action="delete";


    Should I use HTTPAPI to issue simple requests like that?  Or am I
    trying to use the wrong tool?

    Thank you


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