Using makeWebRequest to retreive plain text data

Former Member
Former Member
Hi

I already use makeWebRequest to get json data but have to use it to retreive plain text data. I wrote the following code

function loadTextFromUrl( url )
{
var params = {
};

var headers = {
// body will be encoded as 'a=1&b=2'
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
};

var options = {
:method => Comm.HTTP_REQUEST_METHOD_GET,
:headers => headers,
:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED
};

Comm.makeWebRequest(
url,
params,
options,
method(:onReceive)
);
}


the call to makeWebRequest is OK but I get a -400 error (INVALID_HTTP_BODY_IN_NETWORK_RESPONSE). I guess the system tries to decode the received data but I just need to get plain text data.

Is it possible ? How should I call makeWebRequest then ?

Thx
  • Horsetooth

    Here is the code from the View class. I kind of hacked it together with your request and the WebRequest sample.

    //
    // Copyright 2016 by Garmin Ltd. or its subsidiaries.
    // Subject to Garmin SDK License Agreement and Wearables
    // Application Developer Agreement.
    //

    using Toybox.Communications;
    using Toybox.WatchUi;

    class WebRequestDelegate extends WatchUi.BehaviorDelegate {
    var notify;

    // Handle menu button press
    function onMenu() {
    makeRequest();
    return true;
    }

    function onSelect() {
    makeRequest();
    return true;
    }

    function makeRequest() {


    Communications.makeWebRequest(
    "tynbendad.github.io/.../response-login",
    {
    },
    { :method => Communications.HTTP_REQUEST_METHOD_GET,
    :headers => { // set headers
    "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED
    },
    :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
    },
    method(:onReceiveLogin)
    );
    }

    // Set up the callback to the view
    function initialize(handler) {
    WatchUi.BehaviorDelegate.initialize();

    }

    // Receive the data from the web request
    function onReceiveLogin(responseCode, data) {
    System.println("in onReceive, responseCode=" + responseCode + ", data=" + data);
    }
    }





    This should mimic what you posted earlier and gives me the App Store ID of something I believe.

    Thanks,
    - Coleman
  • Horsetooth



    This should mimic what you posted earlier and gives me the App Store ID of something I believe.

    Thanks,
    - Coleman


    thanks - I haven't gotten to trying this yet but assume it will work, i need to reinstall fresh eclipse/sdks... but, i have a question: the 3.0 beta 2 sdk looked like it only supported a few watches - are all the connect iq 2 watches going to be supported with 3.0, or will the new apis (like text web requests) only work on the very latest watches?
    thanks
  • Ok, here's a chart from the Summit of what devices will be getting CIQ3. The new and just announced things like the va3 Music and the Fenix5 plus devices aren't on it, but it's probably safe to say the'll get CIQ3

    https://forums.garmin.com/forum/developers/connect-iq/1336767-ciq-3-0-on-only-4-devices?p=1336880#post1336880

    If you look at the API doc for 3.0.0 beta 2, TEXT_PLAIN has "Since 3.0.0", so it won't be on devices that stay on CIQ2