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.

  • Send the same exact request to your website and log exactly everything, including headers.

    Then recreate the request to the original website based on the captured data. Probably you'll be able to reproduce the 400

  • I found the issue. I use a very long query string. Seems the simulator had no issue with that, but on the real watch, the query string got truncated, leading to the 400 response from the server.

    And this is the very first time ChatGPT was of actual help with coding. The query string is a jq filter, and ChatGPT gave me a shortened version that worked as well.

    I also tried ChatGPT a bit for questions regarding issues with Monkey C and the CIQ SDK, but for that it is crap, almost all answers I got were factually incorrect.

  • Yeah, I also tried ChatGPT, Gemini and GitHub Copilot. Their 1st answer to simple things was ok, but once I started to ask more specific things they were all just hallucinating. When I pointed this out, they apologized, gave another (usually wrong) answer, and then at the next question they repeated the same mistake that they just apologized for... Crap goes in, crap goes out. What do they see? The handful of samples, some code in GitHub (maybe not even knowing about some of them that it's Monkey C), lot of bad code here in the forum.

    My questions were about algorithms about location, distance, algorithms. As far as I can tell the algorithm part was ok, but they used some functions that do not exist in the SDK, probably they do in some other language.

  • I have the same experience. ChatGPT is usually OK with simpler Pythons scripts, TS or some C++, even assembler for 6502 looked okay, also works fine with certain simpler math problems and well-known algorithms, but it still needs to be checked. However when it comes to Monkey C it can't make head nor tail of it. But this is not an exception, the same applies for more well-known frameworks with much larger communities. 

    Despite this it is quite a time saver for repeating and boring tasks.

  • This issue took another turn, after I made changes again to the jq filter in the URL qery string. My assumption about the length of the URL causing the issue was wrong, actually it was spaces in the jq filter that I escaped as "%20". This works in the simulator but not on the device. However, when I escape the spaces as "+", it does work also on the device.

  • And that should be both documented and "fixed" (so the simulator behaves as real device) If you open a bug report I'll vote for it

  • Space/+ means your don't use encodeURL() and + means you don't use parameters.

  • No, I am not using encodeURL(), basically I was adding the %20 myself to the query string. Not sure if it would make a difference if I use encodeURL() to do that, but I'll try.

    What do you mean exactly by "+ means you don't use parameters"?

  • Usually + is used to build parameters list. Why do you escape space as +?

    You have to use API correctly, I had a problem when I tried to put parameters in url instead of parameters calling makeWebRequest

  • I stumbled upon the + when looking for alternatives for the %20. As per the W3C specification it is the escape characters for spaces in the query string. Here a quote from the specification: "Within the query string, the plus sign is reserved as shorthand notation for a space."

    https://www.w3.org/Addressing/URL/uri-spec.html

    But thanks for pointing out the parameters, I was honestly not aware that there is a separate parameter for that.

    I'll give it a try.