01-25-2018 14:54
01-25-2018 14:54
I've found a couple of similar posts - it seems the Companion is very picky With the fetch.
I have copied an example (Bart), and modified it to my needs.
When I change the URL to non-json resources, the Companion is able to do the fetch, so there is something it can't cope with with my back-end, but I get no information about what actually goes wrong - only "TypeError Failed to fetch"
I could be able to actually change the way the back end responds, but I do not know what to change.
The data is downloaded nicely With chrome on the phone, and various browsers on the computer. The response header looks like this in Firefox:
Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Server: Kestrel
X-Powered-By: ASP.NET
Set-Cookie: .AspNetCore.Session=C2<*** cut for brewety ***> uit5oAkrcMzx2C%2FC; path=/; samesite=lax; httponly
ARRAffinity=eaaff9648d472c3da0da1bd2c3d7451e441df96704916ba7b506b6150b26cdc7;Path=/;HttpOnly;Domain=<** my service **>.azurewebsites.net
Date: Thu, 25 Jan 2018 21:54:50 GMT
The payload looks like this (cut a bit)
[{"displayName":"<one account name>","publicReference":"61914","saldo":1000.200},{"displayName":"<another account name>","publicReference":"30633","saldo":2000.870}]
Answered! Go to the Best Answer.
01-27-2018 11:32 - edited 01-31-2018 01:47
01-27-2018 11:32 - edited 01-31-2018 01:47
Thank you for the suggestion.
I have now solved the problems, and the app is working.
Along my way to fixing this, one of the things I did was to add CORS-support to the back-end.
I got another error along my way, which was the one active when I asked the question - and this might be a result of my inexperience with Javascript and fetch(). The problem I used the most time fixing was that a "console.log(<something>)" caused subsequent <obj>.json() to fail with the TypeError.
Some tips from a newbie to another...
* read this https://developers.google.com/web/updates/2015/03/introduction-to-fetch
* debug the code locally with developer tools in Chrome https://developers.google.com/web/tools/chrome-devtools/javascript/ - the snippets feature is invaluable.
01-26-2018 12:39 - edited 01-26-2018 12:40
01-26-2018 12:39 - edited 01-26-2018 12:40
Does your back-end specify a "Access-Control-Allow-Origin" header? I don't see it in your response header you provided and sometimes that might be the issue.
01-27-2018 11:32 - edited 01-31-2018 01:47
01-27-2018 11:32 - edited 01-31-2018 01:47
Thank you for the suggestion.
I have now solved the problems, and the app is working.
Along my way to fixing this, one of the things I did was to add CORS-support to the back-end.
I got another error along my way, which was the one active when I asked the question - and this might be a result of my inexperience with Javascript and fetch(). The problem I used the most time fixing was that a "console.log(<something>)" caused subsequent <obj>.json() to fail with the TypeError.
Some tips from a newbie to another...
* read this https://developers.google.com/web/updates/2015/03/introduction-to-fetch
* debug the code locally with developer tools in Chrome https://developers.google.com/web/tools/chrome-devtools/javascript/ - the snippets feature is invaluable.