makeWebRequest() returns 402 while getting rest response

Former Member
Former Member
Hi,
I am getting 402 error code from below code. 402 is NETWORK_RESPONSE_TOO_LARGE ?
If yes.. is there any other way to read this response ? It has 2MB of size. Garmin has 100MB of ram yes ? Is it because I have no space left on my device and could clear some unnecessary data ? Or is it prohibited by the API ? Or maybe the background ServiceDelegate invoking the requests is limited by memory ? Maybe I could stream the content somehow ? I would love to have lineIterator like in Java. I don't need the whole file, just to find correct lines and store in memory. I didn't know how to do that, so I am downloading whole file for further processing. On the other hand 2MB is not big size... why there is a problem.. What is the maximum size of response? Can I rewrite the code somehow to accept bigger size ?

(:background)
class WebRequestDelegate extends Toybox.System.ServiceDelegate

function makeRequest() {
Sys.println("makeRequest :)");
// notify.invoke("Executing\nRequest");
try {
Comm.makeWebRequest(
"someaddresswith2mbarray",
null,

{
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON
},
method(:onReceive)
);
} catch (e instanceof Lang.Exception) {
Sys.println(e.getErrorMessage());
}
}
function onReceive(responseCode, data) {

Sys.println("onReceive :)"+responseCode);
}
  • For data fields and watchfaces, makeWebRequest can only be done in the background. For widgets and device app, it can be done in the background or foreground (main) app.

    8k for Background.exit() can't be changed.

    Some of that involves how backgrounding works. The main app doesn't need to be running when the background runs, and anything returned by Background.exit() won't be seen by the main app until it runs again. You can prompt the user if the main process should run when the background has something for it. By default, if the background had run and something was queued for the main app, and runs again, what was queued is replaced by the new data

    Once you register a temporal event, say for every 5 minutes, it will run every 5 minutes 24/7. Based on the data you are getting and what it's used for, you may want to delete the temporal event when your app exits

    here's a blog post that goes into backgrounding a bit more