I can make simple GET requests with makeWebRequest()
to https://captive.apple.com with the simulator however, when I side load the app onto a Garmin VivoActive 3 (SW Version 6.4, Connect IQ 3.0.10) which is connected via bluetooth to an Android version of the Garmin Connect App (version 4.2). The request fails with a response of -400
(INVALID_HTTP_BODY_IN_NETWORK_RESPONSE
) and null
data. The phone can access https://captive.apple.com via its web browser. Why would this be different on the device and how do I resolve it?
Below is the code:
using Toybox.System
using Toybox.Communications
function onReceive(responseCode, data) {
if (responseCode == 200) {
System.println("Request Successful");
System.println("Response: " + responseCode + " Data: " + data);
}
else {
System.println("Response: " + responseCode + " Data: " + data);
}
}
function makeRequest(action) {
var url = "https://captive.apple.com";
var params = {};
var options = { // set the options
:method => Communications.HTTP_REQUEST_METHOD_GET,
:headers => {
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN
};
var responseCallback = method(:onReceive);
Communications.makeWebRequest(url, params, options, method(:onReceive));
}
Also, If I change the URL to the non-https version (http://captive.apple.com) on the device I get a -300
(NETWORK_REQUEST_TIMED_OUT
) response and null
data. Is this due to the watch only allowing the use of HTTPS?
Thanks