Facility Control

 View Only
  • 1.  POST request with added header

    Posted 10-07-2020 14:56

    Is there a way to include a header with a POST request (either asyncPost or asyncHTTP)? I need to include an "Authorization-Token" header to authenticate on the other end.



  • 2.  RE: POST request with added header

    Posted 10-19-2020 17:51

    Yes, you can write headers.   Here is an example:

     

      var baseUrl = params.getParam('config', 'statsApi.url', 0).getValueAsString();
      var user = params.getValue('statsApi.user', 0);
      var pass = params.getValue('statsApi.pass', 0);
      var encStr = Base64.encode(user + ':' + pass);

      headers["accept"] = "application/x-www-form-urlencoded";
      headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36";
      headers["Authorization"] = "Basic " + encStr;
      headers["Content-Length"] = 0;

      ogscript.asyncHTTP(baseUrl, "POST", headers, '', callback);

     

    Let me know if you need more guidance than that.

     


    #DashBoard


  • 3.  RE: POST request with added header

    Posted 10-21-2020 19:01

    Thanks, Ben! Last example I had seen of asyncHTTP was just a string, not an array, for headers, so I didn't think to try that. Thanks! Works great! I did declare 'headers' before using it, in case anyone needs it, with:

    var headers = {};

    #DashBoard