Error on the 2nd request due to HTTP_POINT_ADDL_HEADER

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
KKT
Posts: 8
Joined: Thu Apr 28, 2022 8:05 am

Error on the 2nd request due to HTTP_POINT_ADDL_HEADER

Post by KKT »

Hi All,
I am using two http_req in my program. First one to fetch the authorisation code( this doesnt reuqire any additional headers ) second one to post my data( this requires additional headers ). When I run my programs the first time all works fine, but, when try it again ( without logging out and loggin in or in intreative more instead of batch ) I get 400 error for my authorisation code fetch request. When i debug i see that the additional headers are being added for the first request also. Any help in resolvng this is really appriciate.
Is this issue happening due to keep alive? My code sinppet is as below:
For fetch token :

Code: Select all

http_setOption( 'content-type' : 'application/x-www-form-urlencoded' );
http_debug(*On: '/tmp/HcfCwJsnDebuglog.txt');
rc = http_req( 'POST'              
              : %Trim( TokenUrl )
                : %Trim( TokenResp )                       
               : *Omit                                      
               : *Omit                                      
               : %Trim( TokenPayload ) );                 
 If rc <>1;                                                                                  
    errorMsg = http_error( xErrorNo );                      
    http_comp('Error!     xErrorNo: '  + %Char(xErrorNo) +  
                              '   errorMsg:  ' + errorMsg );                                  
 Else;                            
    http_comp('Success!' );     
 EndIf;                      
2nd request to post the data:

Code: Select all

http_setOption( 'content-type' : 'application/json' );
http_xproc( HTTP_POINT_ADDL_HEADER : %paddr(addSpecialHeaders)
Monitor;                        
   rc = http_req( 'POST'        
                 : %Trim( Url ) 
                : %Trim( Response )    
                : *Omit                  
                : *Omit                  
                : %Trim( Payload ) );  
  If rc <>1;   
    errorMsg = http_error( xErrorNo );                      
    http_comp('Error!     xErrorNo: '  + %Char(xErrorNo) +  
                              '   errorMsg:  ' + errorMsg );                                  
 Else;                            
    http_comp('Success!' );     
 EndIf;
 
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Error on the 2nd request due to HTTP_POINT_ADDL_HEADER

Post by Scott Klement »

Hi KKT,

When you post code, place [code] before the first line, and [/code] after the last line, it will make your code much easier to read, and that makes me happy :-) I added them to your post.

Once you set an option with http_xproc() (as well as various other things) it remains in the memory of the activation group, allowing your routine to be used for all HTTP requests.

If you want to disable the additional headers, you may turn them off deliberately after your 2nd request like this:

Code: Select all

http_xproc( HTTP_POINT_ADDL_HEADER : *NULL);
KKT
Posts: 8
Joined: Thu Apr 28, 2022 8:05 am

Re: Error on the 2nd request due to HTTP_POINT_ADDL_HEADER

Post by KKT »

Hi Scott,
It worked like a Charm! Thanks a Lot.
I'll ensure that next time I post the question I'll do it as instructed and make it as legible as possible.
Post Reply