Hello,
I'm really new to Garmin App Development, I work on a personal project whom consist to make a simple Garmin Widget to show some retrieved data from an URL.
I get a HTTP response, and I'm wondering how could I access the text in the body section.
In my View.mc file :
class BusApp3View extends WatchUi.View { function initialize() { View.initialize(); } function onLayout(dc as Dc) as Void { setLayout(Rez.Layouts.MainLayout(dc)); } function onShow() as Void { } // Update the view function onUpdate(dc as Dc) as Void { var JT = new JsonTransaction(); JT.makeRequest(); View.onUpdate(dc); } function onHide() as Void { } } class JsonTransaction { // set up the response callback function function onReceive(responseCode as Number, data as Dictionary) as Void { if (responseCode == 200) { // print success } else { var response_text = "Fail"; // print response code } } function makeRequest() as Void { var url = "https://testgarminq.azurewebsites.net/"; // set the url var params = { // set the parameters }; var options = { // set the options :method => Communications.HTTP_REQUEST_METHOD_GET, // set HTTP method :headers => { // set headers "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED}, // set response type :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED }; var responseCallback = method(:onReceive); // set responseCallback to // onReceive() method // Make the Communications.makeWebRequest() call Communications.makeWebRequest(url, params, options, method(:onReceive)); } }
Thanks for your help !