MakeWebRequest error -200 on device only with iOS phone. (parameters in url issue)

Hi,

Are there a friendly Fenix 6 owner around here, that are willing to help me with a couple of hopefully quick tests???

I have been hacking away on an app that's uses the MakeWebRequest. The starting point was garmins WebRequest sample. Works fine in the sim and on my venu2 and VA3 devices. But when sideloaded onto my friends fenix 6, it throws an error -202.

Originally I just replaced the url in the garmin example, but have now also added 

:method => Communications.HTTP_REQUEST_METHOD_GET
to "option" as the -202 indicated invalid method. And the docs don't say there's a default....
Still works in sim for F6 and on my devices, but not on F6 hardware.
I plan to try to change this to JSON 
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
and also split the url into 2 and use the parameters. But with several days turn around for a test, it became clear that VS code and a fenix 6 needed to be brought closer together....  
My code looks like this now. For some reason the Insert->code function says I'm block on the forum, so I can't make it look nice here...
Can some please drop this into the garmin sample->WebRequest and run it on Fenix 6 hardware??? And maybe run the clean garmin sample first.
Thanks in advance.
Jesper.
//! Make the web request
public function makeRequest() as Void {
var url = "">api.energidataservice.dk/.../Elspotprices;

var options = {
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON,
:method => Communications.HTTP_REQUEST_METHOD_GET,
:headers => {
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON    //Not yet tested on device with JSON
}
};
Communications.makeWebRequest(
url,
{},
options,
method(:onReceive)
);
}

//! Receive the data from the web request
//! @param responseCode The server response code
//! @param data Content from a successful request
public function onReceive(responseCode as Number, data as Dictionary?) as Void {
if (responseCode == 200) {
var buff = data.get("records");

for(var h = 0; h < buff.size(); h++){
var buff2 = buff[h];
var buff3 = ((buff2.get("SpotPriceDKK") / 10.0).toNumber()).toString();
var buff4 = buff2.get("HourDK");
System.println(h + "=>" + buff3 + " " + buff4 + "##");
}

_notify.invoke(data);
} else {
_notify.invoke("Err: " + responseCode.toString());
}
}


  • argh. Looks like the url got censored...

    Should be

    h t t p s : / / api.energidataservice.dk/dataset/Elspotprices?start=now-PT1H&end=%22now+P1D%22&filter={%22PriceArea%22:%22DK1%22}

  • you don't want to include parameters as part of the url. You want to use params in the makeWebRequest. (what you have as {} in the call)

    Between you and your friend, it's likely a Android vs iOS difference.

  • Yeah, I saw you mention the param stuff in an old post. That's why I wanted to try that. 

    He does indeed use ios, while I'm using the green garbage bin. If you believe iOS+param in url is the problem, I guess I can give him one more try...

    Thx Jim.

  • Having the params as part of the URL worked with Android but not iOS in the past.

  • OK. Seems to be the same today. So Garmin, please please look into this. The sim, ios and android connected devices should behave just somewhat similar. Not at all the case today. 

    And btw. It was far from as easy as just moving the params. Took A LOT of tuning afterwards to get the correct response. Adding/removing quotes etc. And it becomes really time consuming, when you have to move it to a device and test with 2 different phones...

    Anyways. I hope that's behind me know, so thanks Jim.

  • Having params as part of the url on iOS has been around probably since CIQ started.  It's not a Garmin isse.  It's how iOS does things vs how Android does things.  If you always separate out your params, no issue. Just pass them as params in the makeWebRequest call.

  • Not sure I agree on the "no issue" part :-)

    Ok, but couldn't they make it so the sim would throw a error -202 then? Should be easy to detect ?blabla in the url

    Maybe even a warning at build time.

    And as a minimum make it clear in the documentation. Under the param they state

    • These values should not be URL encoded.

    but there is no mention under url, that any params here will ruin the party (for ios)....

    That one sentence there would have saved CIQ newbies like me many many hours.... And you a few too.... And probably not the first or last time you see this in the forum.

  • As the sim doesn't use Android or iOS, it can do things differently than on a real device, and on real devices it may use Wifi and neither phone type,

    The only time this has cost me is folks with iOS that don't handle params correctly and posting about it

  • I have a similar problem. In a widget I'm controlling my smart home with WebRequests, it works fine, expect for one case.
    To increase/decrease the brightness of a lamp, I need to send this request:
    h t t p s : //xyz/command/floodlight_set_config?config={"intensity":50}

    It doesn't work on my Fenix 7s. I'm using iOS
    As Jim already explained, this is because of the parameter directly in the url.

    I want to use it as parameters, but the syntax how to do it, is not clear for me.

    I tried this and several variations, but no success:

    var params = { "config" => [{"intensity" => 50}]};
    
    var options = {:method => Communications.HTTP_REQUEST_METHOD_GET, 
                   :headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON},
        		   :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON};
    
    var url = ".../command/floodlight_set_config";
    
    Communications.makeWebRequest(url, params, options, method(:onReceive));
    

    Depending what I use "Content-Type" and/or "responseType" I get either -202 or -400.

    I think I made something wrong with the syntax of the parameter?
    Can someone enlighten me please

  • Have you tried escaping the quotes around intensity like \" ??

    Mine now. Look at the filter.
    param = {"start" => "now-PT1H", "end" => "\"now+P2D\"", "filter" => "{\"PriceArea\":\"DK1\"}"};

    That's what I ended up doing to get mine working. Not sure if the square bracket does the same or what they do...

    Also, in the sim you can go File->View HTTP Traffic and find the ">Header" so you can see what ends up going on the wire...