Thanks Scott. This is really very helpful information.
I installed the latest HTTPAPI version and tested using http_req
procedure and it works like a charm. As of now, these are the 2
challenges I faced while testing:
1. My program which invokes http_url is fully free and was not
compiling due to error "*The type and attributes of the parameter do
not match those of the prototype*" when i defined the response parm as
(dcl-s ResponseMessage varchar(1600000) ;). In prototype it's
defined as below.
*D ResultStr a len(16000000) varying
options(*varsize:*omit:*nopass) *
I changed the prototype to below and then it got compiled. Please
advise if i shouldn't be changing prototype definition.
*D ResultStr 1600000a varying
options(*varsize:*omit:*nopass)*
2. For testing, when i changed my URL to make it invalid just to
determine if i get valid error message. I got an error "*Pointer not
set for location referenced*" in module *COMMTCPR4*, procedure
*CommTcp_Hangup*. Error is coming on *close(fd)* statement.
D CommTcp_Hangup...
D PI 1N
D peHandle * value
c eval p_CommTcp = peHandle
*c if close(fd) = 0 *
c return *ON
c else
c return *OFF
c endif
P E
call PGM(TESTWEB2)
(GSKit) Peer not recognized or badly formatted message received.
Pointer not set for location referenced.
The call to HTTP_REQ ended in error (C G D F).
Thanks,
Pargat
On Thu, May 4, 2017 at 12:15 AM, Scott Klement <sk@xxxxxxxxxxxxxxxx
<mailto:sk@xxxxxxxxxxxxxxxx>> wrote:
Pargat,
There are older routines and newer routines in HTTPAPI. I would
recommend using the newer ones if you can, they have a much more
streamlined and simple interface. Use the older routines if you
need compatibility with older OS versions, including versions of
RPG before it supported larger strings.
Under the covers, all of the ways of doing POST use the same HTTP
POST request. The difference is how they interface to your program.
The old methods for POST are:
-- http_url_post(): Data to upload comes from a pointer, data
received goes to a file in the IFS
-- http_url_post_raw(): Data to upload comes from a pointer,
received data goes to a callback routine.
-- http_url_post_stmf(): Data to upload comes from an IFS file,
received data goes to a file.
-- http_url_post_raw2(): Callback is used for both the data to
upload, and the received data
-- http_url_post_xml(): Data to upload comes from a pointer. Data
received is parsed by an XML parser, and parsed data is passed to
two callbacks.
The new methods are:
-- http_req(): Works with any operation, including POST. Data to
upload can come from a file or a string. Data received also can
be a file or string.
-- http_string(): streamlined version of http_req(). Input and
output are both strings. Errors are sent as *escape messages
instead of return codes.
-- http_stmf(): streamlined version o http_req() where
input/output are both files. Errors are sent as *escape messages.
Please do not call HTTPCMDR4 directly, that is only meant for use
from the HTTPAPI command object, and I cannot provide support for
calling this program directly.
Given that you don't want special behavior for errors, http_req()
might be easiest.
url = 'http://your-url-here';
rc = http_req('POST': url: *omit: OutputString: *omit:
InputString: 'application/json');
the rc will tell you what you got back from the server.
-1 = error occurred, communications didn't succeed
0 = time out
1 = success (same as 200 HTTP code)
numbers higher than 1 are HTTP response codes that were sent from
the server, such as 404 (not found), 403 (forbidden), 500 (server
detected error), etc. If you get a number higher than 0 in the
rc, you will also have data in the OutputString (if the server
sent any.)
Good luck!
On 5/3/17 10:35 AM, Pargat Singh wrote:
Hi,
I'm very new to HTTPAPI so need a little help here, sorry might
be asking basic/stupid questions.
I need to post data as named value pair and data is embedded in
URL itself, example below. I was planning to use HTTPAPI command
but I believe that won't return me error message back in program.
So other option is to call HTTPCMDR4 program with required parms
and it will return me error code and message back in my calling
program.
Not sure if i should be calling this program or use any other
procedure e.g. http_url_post_raw2. But with this not sure how to
trap the error message if connection/POST is not successful.
https://xyz.com/048216022518/RTI_TRAX_Q?Action=SendMessage&
<https://xyz.com/048216022518/RTI_TRAX_Q?Action=SendMessage&>*MessageBody=Loc:6030,Type=FRZ,SKN:423465768675,Qty:1000*
*
*
In addition, i need to send data in JSON format so i used Scott's
YAJL utility and tried to generate data as it's shown in Scott's
example. But when i check the http log it shows junk characters,
below is snippet from http log file. In debug, it shows junk too
but i believe that might be due to EBCDIC vs 1208. In debug i
pulled HEX equivalent of data which was showing in program
variable and then converted to ASCII format. It showed correctly
but not sure why it's transmitting as junk. Below message was
posted on remote system with just "-" and rest of the data was
ignored/not transmitted. Please help.
do_oper(POST): entered
There are 0 cookies in the cache
POST /048216022518/RTI_TRAX_Q?Action=SendMessage&MessageBody=-#
<?Ä/ÈÑ?> ë?ÍÊÄÁ ï(ë éÍ/>ÈÑÈ` '
Host: sqs.us-east-1.amazonaws.com
<http://sqs.us-east-1.amazonaws.com>
User-Agent: http-api/1.32
Thanks,
Pargat
--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx <mailto:Ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
http://scottklement.com/mailman/listinfo/ftpapi
<http://scottklement.com/mailman/listinfo/ftpapi>