Headers in Communications request

Former Member
Former Member
I try to implement a very simple Garmin Connect IQ app that downloads some tiny json data from a webservice. Webservice authentication is HTTP basic.

I try to implement it like this:

var authString = StringUtil.encodeBase64("someusername:somepassword");
authString = "Basic " + authString;

Comm.makeWebRequest(
"somewebserviceurl,
{

},
{
"Headers" => { "Authorization" => authString }
},
method(:onReceive)
);
It does not fetch the response, responsecode is 0, so it is not informative at all. If I try calling any webservice that does not need any authentication, it works, so the problem is the basic authentication.

What can be the problem? Thanks very much in advance!
  • There are two issues with your code.

    • the key in the options map is :headers, not "Headers". The former is a symbol and the latter is a string (see the docs).
    • you should specify your request parameters in the params parameter.


    var url = "somewebserviceurl";

    var params = {
    "param" => 1
    };

    var options = {
    :headers => {
    "Authorization" => "Basic " + StringUtil.encodeBase64(Lang.format("$1$:$2$", [ someusername, somepassword ]))
    }
    };

    Comm.makeWebRequest(url, params, options, method(:onReceive));
  • Former Member
    Former Member over 8 years ago
    Thanks a lot, it works! :)