Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-17544

Function CurlHttpRequest.AddHeader not working as documented

XMLWordPrintable

      I am developing webhook integration with third party application that requires authorization via tokens in headers.

      When I use this code:

      json = ....
      ...
      req = new CurlHttpRequest();
      req.AddHeader('Content-Type', 'application/json'); 
      req.AddHeader('Auth-Token', params.user_token);
      req.AddHeader('User-Id', params.user_id);
      ...
      resp = req.Post(url, JSON.stringify(json));
      ...

      I receive status code 401 with message "You must be logged in to do this." from third party application.

       

      But when I use this code

      json = ....
      ...
      req.AddHeader('Content-Type: application/json');
      req.AddHeader('Auth-Token: ' + params.user_token);
      req.AddHeader('User-Id: ' + params.user_id);
      ...
      resp = req.Post(url, JSON.stringify(json));
      ...

      everything works fine and I receive code 200.

      From this I concluded that setting the headers does not work correctly in the first code example.

      According to this documentation, I pass two parameters to AddHeader function, but this not working as expected. But code examples (in the documentation) use string concatenation instead of passing two parameters and this working great.

      Where is the mistake? In the documentation or code examples?

            zabbix.dev Zabbix Development Team
            alex_spq Alex Alexandrov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: