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

http post xml question



   I need to use HTTPAPI to interact with a web service.  I've got a url
   that I need to hit with some xml behind it.  I'm having to do this in
   order to interact with 3rd party software from our ERP applications.
   They've given me a url that they said would work if I click on it and
   it does.  Once I launched the URL I had to view source to see the
   actual response, but regardless, I've verified that it works.
   The format of the url is something like this
   http://ip:port/Action.do?<?xml%20version='1.0'%20encoding='UTF-8'?>&in
   put=<mainElement><stuff1>ABC</stuff1><stuff2>123</stuff2></mainElement
   >
   What I need to do is do a post of that url and xml and then receive
   the response back, which will be in xml, and parse it in to fields in
   the RPG program.  What is the best way to do it? Should I use
   http_url_post_xml or http_url_post_stmf_xml or http_url_post_stmf?
   It's all kinda confusing.  Especially when I have a pretty good idea
   of what I want to do.  I just don't know which tools to use to do it.
   I just want to mimic the action of the example url that was given to
   me.
   I'm attaching the code I've been using so far without any luck.  I can
   hit the 3rd party server, but they just see an empty string where my
   xml is supposed to be.
   Thanks for any help.  Example code would be awesome if anyone knows
   how to fix this.
000100060210      *  This is an example of calling a SOAP Web service w/HTTPAPI.
000200060210      *
000300060210      *  This sample calls the Currency Exchange Rate Web service
000400060310      *  provided by WebserviceX.net. For more info, search for it
000500060310      *  at   http://www.WebserviceX.net
000600060210      *
000700060210      *  To Compile (requires V5R1):
000800060323      *     CRTBNDRPG PGM(EXAMPLE18) SRCFILE(libhttp/QRPGLESRC)
000900060210      *
001000060210      *  To Run:
001100060310      *     CALL EXAMPLE18 PARM('USD' 'JPY' 12.00)
001200060210      *
001300060210      *  (This shows the value of USD 12.00 in Japanese currency.)
001400060210      *
001500060324     H DFTACTGRP(*NO) BNDDIR('HTTPAPI':'QC2LE')
001600060206
001700090202     D* EXAMPLE18       PR                  ExtPgm('EXAMPLE18')
001800090202     D*  Country1                     3A   const
001900090202     D*  Country2                     3A   const
002000090202     D*  Amount                      15P 5 const
002100090203     D* EXAMPLE18       PI
002200090202     D*  Country1                     3A   const
002300090202     D*  Country2                     3A   const
002400090202     D*  Amount                      15P 5 const
002500060206
002600060206      /copy httpapi_h
002700060206
002800060206     D Incoming        PR
002900090224     D   rate                         8A
003000060206     D   depth                       10I 0 value
003100060206     D   name                      1024A   varying const
003200060206     D   path                     24576A   varying const
003300070912     D   value                    65535A   varying const
003400060206     D   attrs                         *   dim(32767)
003500060206     D                                     const options(*varsize)
003600060206
003700090202     D TREE            s          32767A   varying
003800060206     D rc              s             10I 0
003900090224     D rate            s              8A
004000090224     D Result          s             12A
004100060206
004200060206      /free
004300070912
004900070912
005000070912       // Note:  http_debug(*ON/*OFF) can be used to turn debugging
005100070912       //        on and off.  When debugging is turned on, diagnostic
005200070912       //        info is written to an IFS file named
005300070912       //        /tmp/httpapi_debug.txt
005400070912
005500090225       http_debug(*ON);
005600070912
005700070912       // Note:  http_XmlStripCRLF(*ON/*OFF) controls whether or not
005800070912       //        the XML parser removes CR and LF characters from the
005900070912       //        Xml data that's passed to your 'Incoming' procedure.
006000070912
006100070912       http_XmlStripCRLF(*ON);
006200070601
006300090202       TREE =
006500090202        '<Request>'
006600090225       +'<transactionId>123456</transactionId>'
006900090225       +'<lineItems>'
007000090225       +'<LineItem>'
007100090225       +'<lineItemId>123xyz</lineItemId>'
007307090225       +'</LineItem>'
007308090225       +'</lineItems>'
007400090202       +'</Request>';
007500070426
007700060206
007800060310       rc = http_url_post_xml(
007900090225                  'http://IP:PORT/'
007901090225                 +'Action.do?'
007902090225                 +'<?xml%20version=%271.0%27%20encoding=%27UTF-8%27?>'
007903090225                 +'&input='
008000090225                         : %addr(TREE) + 2
008100090202                         : %len(TREE)
008200060206                         : *NULL
008300060206                         : %paddr(Incoming)
008400060206                         : %addr(rate)
008500060206                         : HTTP_TIMEOUT
008600060206                         : HTTP_USERAGENT
008700060206                         : 'text/xml'
008800090202                         : *blanks );
008801090225
008900060206
009000060206       if (rc <> 1);
009100060210          http_crash();
009200060206       else;
009300090202          Result = rate;
009301090224          dsply Result;
009400090224          http_comp(%trim(Result));
009600060206       endif;
009700060206
009800060206       *inlr = *on;
009900060206
010000060206      /end-free
010100060206
010200060206     P Incoming        B
010300060206     D Incoming        PI
010400090224     D   rate                         8A
010500060206     D   depth                       10I 0 value
010600060206     D   name                      1024A   varying const
010700060206     D   path                     24576A   varying const
010800070912     D   value                    65535A   varying const
010900060206     D   attrs                         *   dim(32767)
011000060206     D                                     const options(*varsize)
011100060324
011200090224     D atof            PR             8A   extproc('atof')
011300060324     D   string                        *   value options(*string)
011400060206
011500060206      /free
011600090202          if (name = 'lineItemId');
011700060324             rate = atof(value);
011800060206          endif;
011900060206      /end-free
012000060206     P                 E
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------