How to add custom http headers

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
jasanchez
Posts: 3
Joined: Thu Aug 03, 2023 2:49 am

How to add custom http headers

Post by jasanchez »

Hi,

It may have already been asked, but I just can't find it.
How do I add custom http headers, like x-date?

Thanks.

Javier Sanchez
jonboy49
Posts: 263
Joined: Wed Jul 28, 2021 8:18 pm

Re: How to add custom http headers

Post by jonboy49 »

You use the http_xproc API with the first parameter of HTTP_POINT_ADDL_HEADER to specify your custom routine to be called and then build the required header content in that procedure.

Here's how I use it with Zoom APIs - this call has to occur before you invoke the http_string or whatever of the http APIs you are using to invoke the web service.

Code: Select all

   // Notify httpapi of the routine to use to add headers
   http_xproc( HTTP_POINT_ADDL_HEADER
             : %paddr(addSpecialHeaders)
             : %addr(authorizationToken) );
The actual addSpecialHeaders() routine looks like this:

Code: Select all

// AddSpecialHeaders
//   Called by httpapi to add the headers
//   In this case the header is just the authentication token (the JWT)

Dcl-Proc addSpecialHeaders;
   Dcl-Pi *N;
      headersToAdd    Varchar(32767);
      var             like(authorizationToken) const;
   End-Pi;

   Dcl-c  CRLF  x'0d25';

   headersToAdd = 'authorization: ' + var + CRLF;

End-Proc;
jasanchez
Posts: 3
Joined: Thu Aug 03, 2023 2:49 am

Re: How to add custom http headers

Post by jasanchez »

Excelent!
Thank you!!!!!
ray.marsh
Posts: 7
Joined: Fri Aug 08, 2025 12:58 pm

Re: How to add custom http headers

Post by ray.marsh »

This is great information. Solved my issue with calling an AWS web-service that requires an API-Key.
Thank you very much.
Giel
Posts: 6
Joined: Tue Nov 21, 2023 4:40 am

Re: How to add custom http headers

Post by Giel »

Hi there, I am struggling to get the api call with an api key to work. Would you mind sharing your code for the sub proc
I keep getting this error : connect(2): A remote host refused an attempted connect operation.
Scott Klement
Site Admin
Posts: 985
Joined: Sun Jul 04, 2021 5:12 am

Re: How to add custom http headers

Post by Scott Klement »

Giel wrote: Tue Jun 02, 2026 1:52 pm Hi there, I am struggling to get the api call with an api key to work. Would you mind sharing your code for the sub proc
I keep getting this error : connect(2): A remote host refused an attempted connect operation.
This has nothing to do with an API key or header. It isn't getting far enough to send the key, it can't even connect.

Either you have the wrong URL, or a firewall is blocking you.
Post Reply