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

Re: [Ftpapi] Procedure to use for POST data



Thanks Scott.
I changed the definition of variable in my program and reverted the change i made in HTTPAPI. After change i retried again and got same error "Pointer not set for location referenced". This is the program I'm testing with, it's happening when i use any invalid URL, e.g. xyz.com

Please let me know if you need more details.

**FREE                            
       /copy qrpglesrc,httpapi_h  
dcl-s  httpurl             varchar(5000)  ;                                       
dcl-s  ResponseMessage     varchar(1600000:4) ;                                   
dcl-s  HttpLogFileIfsPath  varchar(200)   ;                                                                
dcl-s  rc                  zoned(10)  ;                                           
        httpurl      = 'https://xyz.com/048216022518/' +                          
                       'RTI_TRAX_Q?Action="" +             
                       'Loc:6603,Type:CC,SKN:423465,UID:B1234567,' +              
                       'Qty:1000,Seq:1,TimeStamp:2017-04-05-14.15.04.409000' ;    
                                                                                  
        HttpLogFileIfsPath   =  '/home/gurayap/httplog.txt'     ;                 
        http_debug(*ON: HttpLogFileIfsPath);                                      
                                                                                                                                    
        rc  =  http_req('POST'                      
                       : httpurl                    
                       : *omit                      
                       : ResponseMessage            
                       : *omit                      
                       : *omit                      
                       : 'application/json') ;      
                                                    
          *InLr = *On;                              

Below is from log file.

recvresp(): entered                   
HTTP/1.1 200 Connection established   

SetError() #13: HTTP/1.1 200 Connection established                                            
recvresp(): end with 200                                                                       
recvdoc parms: identity 0                                                                      
header_load_cookies() entered                                                                  
SNI hostname set to: xyz.com                                                                   
(GSKit) Peer not recognized or badly formatted message received.                               
ssl_error(415): (GSKit) Peer not recognized or badly formatted message received.               
SetError() #30: SSL Handshake: (GSKit) Peer not recognized or badly formatted message received.
http_close(): entered                                                                          

Thanks,
Pargat                 

On Thu, May 4, 2017 at 5:08 PM, Scott Klement <sk@xxxxxxxxxxxxxxxx> wrote:
Pargat,

I do not recommend changing the prototype in HTTPAPI.  If you are doing this, then you must make sure that it is changed everywhere in HTTPAPI and is not causing problems.  I cannot help you with this, I will not support it if you make your own changes to HTTPAPI, then you must support it yourself.

Instead, please define your variable as varying(4).  (It can be any length).  This will make it compatible with http_req() and you won't need to change the prototype.

I am not familiar with the pointer error you've cited -- please make sure it is not due to an incorrect change you've made to HTTPAPI. If it is not, then please tell me how I should call HTTPAPI to reproduce this problem.

-SK

On 5/4/2017 1:33 PM, Pargat Singh wrote:
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 = "" href="http://your-url-here" rel="noreferrer" target="_blank">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="">
    <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=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@lists.scottklement.com>
    http://scottklement.com/mailman/listinfo/ftpapi
    <http://scottklement.com/mailman/listinfo/ftpapi>





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

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