Webrequest response issue

I had a watch face that I have been testing for a while and recently stopped working. I am looking at the new stuff now, but I cannot figure out what changed.
It is a background webrequest.

Looking at the http traffic logs on the simulator, it seems to work fine in communicating and receiving data.
But in eclipse (and on the watch face) I do not receive the data.
I get this error: Background: Communication Error Code: -400 but in the http logs it is 200.

So I assume is something in the way data are parsed.

It worked with just {:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON }
Now it doesn't anymore.

This is the response I get from the http logs:
In the header:
HTTP/1.1 200 OK\r\n

In the body:
37c\r\n{"status":200,"callCount":1,"copyright":"Tidal data retrieved from www.worldtide.info. Copyright (c) 2014-2017 Brainware LLC. Licensed for use of individual spatial coordinates on behalf of\\/by an end-user. Copyright (c) 2010-2016 Oregon State University. Licensed for individual spatial coordinates via ModEM-Geophysics Inc. NO GUARANTEES ARE MADE ABOUT THE CORRECTNESS OF THIS DATA. You may not use it if anyone or anything could come to harm as a result of using it (e.g. for navigational purposes).","requestLat":9.98,"requestLon":-85.64,"responseLat":10,"responseLon":-85.6667,"atlas":"TPXO_8_v1","requestDatum":"MLLW","responseDatum":"MLLW","extremes":[{"dt":1544482804,"date":"2018-12-10T23:00+0000","height":1.863,"type":"High"},{"dt":1544504290,"date":"2018-12-11T04:58+0000","height":0.17,"type":"Low"},{"dt":1544526199,"date":"2018-12-11T11:03+0000","height":1.951,"type":"High"}]}\r\n0\r\n\r\n

Any help it is greatly appreciated.
  • Thanks HermoT. Sending you a PM. I appreciate the help.
  • Toybox.Communications (garmin.com)

    Just had the same issue ourselves. The GET request worked, then failed with -40x. For us, the problem seems to have been when the :parameters option is "{}". The solution appears to be to set that to either null or "{\n}" (with a newline between curly brackets).

    There's a few hours of my life I won't get back...

  • You want to make sure you don't include parameters as part of the url, but have them as parameters in the makeWebRequest call.  Otherwise you'll see differences between the sim, Android and iOs.

  • I should have added that the behaviour differed between watch and simulation. The simulation worked with :parameters set to "{}", the watch did not.

  • And you may see a difference on a device when it's using an Android or iOS phone.depending on how you deal with parameters.  It could even vary by the version of GCM you are using on either device.

  •     function getDeviceData() as Void {
            var url     = "https://smartdevicemanagement.googleapis.com/v1/enterprises/" + projectId + "/devices/" + Properties.getValue("deviceId");
            var options = {
                :method  => Communications.HTTP_REQUEST_METHOD_GET,
                :headers => {
                    "Content-Type"  => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED,
                    "Authorization" => "Bearer " + Properties.getValue("accessToken")
                },
                :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
            };
    
            if (System.getDeviceSettings().phoneConnected && wifiConnection) {
                Communications.makeWebRequest(url, null, options, method(:onReceiveDeviceData));
            } else {
                System.println("Note - getDeviceData(): No Internet connection, skipping API call.");
            }
        }
    
    No parameters in the URL we supplied (i.e. after a "?" character)
    (Our replies crossed in the ether)