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

Re: [Ftpapi] Procedure to use for POST data



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 = '';
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="">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=""      <?Ä/ÈÑ?>                 ë?ÍÊÄÁ    ï(ë        éÍ/>ÈÑÈ`      '

Host: sqs.us-east-1.amazonaws.com                                                                                                 

User-Agent: http-api/1.32                                                                          



Thanks,

Pargat                               




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