makeWebRequest works in simulator but error 400 on device

Hi,

I currently have an issue with my app. Its web request works fine in the simulator, but when I run it on my watch (Epix 2 Pro) I get a 400 error from makeWebRequest. From the error code being positive I gather it is not an error from the SDK but from the server? HTTP 400 would mean "bad request". Any idea of what could cause this error on the watch, and only on the watch? I already tried to explicitly set the phone OS in the simulator, but still there it works fine.

Edit: tried this with SDK 8.1.0 and 7.1.1, the problem stays the same.

  • The sim works differently than what you might see with iOS or Android, and the thing you want to do, is to not include parameters as part of the URL, but to specify parameters as parameters.  The "+" is used if you try to include the params as part of the URL

    Here for example is what I use for OWM, and it works in the sim, Android, iOS or wifi:

    	    	var UNITS=(Sys.getDeviceSettings().temperatureUnits==Sys.UNIT_STATUTE) ? "imperial" : "metric";
    			var url="https://api.openweathermap.org/data/2.5/weather";
    	    	var param={
    	    		"lat" => latlon[0].toFloat(),
    	    		"lon"=>latlon[1].toFloat(),
    	    		"lang"=>"en",
    	    		"appid"=>APIKEY,
    	    		"units" => UNITS};
    			var options = {
    				:methods => Comm.HTTP_REQUEST_METHOD_GET,
    				:headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
    				:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    			};
       	
    			Comm.makeWebRequest(
    	    	   	url,
    	    	   	param,
    	    	   	options,
    	    	   	method(:receiveWeather));

  • Thanks, with the parameters-parameter it works. I can put in the string with spaces, and it seems to get automatically encoded correctly.

    Not sure why I did not use the parameters in the first place, maybe when I wrote the code the first time I thought those are only for POST requests.

  • If I recall, at one time years ago you could include the parameters as part of the URL in the sim and Android, but not if the phone was iOS.  Something may have changed so it no longer works with Android.

    I've just always used "param" as I show above, with no issues.

  • Do you use documentation? 

    developer.garmin.com/.../Communications.html

    parameters — (Lang.Dictionary) — A Dictionary of keys and values.

    - These values should not be URL encoded.

    -Can be null.

  • It worked fine for me to include them in the URL, both on iOS and Android, I only started having issues when I needed to add spaces to the parameters.

  • Yes, I do use the documentation. But in this case I worked only with the URL and there as far as I know encoding is necessary.

    But anyway, you are right, I should have used the parameters parameter in the first place, and everything would have worked fine.