04-21-2019 12:58
04-21-2019 12:58
After the latest upgrade of SDK to 3.1, Fitbit firmware to 32.33.1.30, and Fitbit Android App to 2.91, I've realized that "fetch" doesn't work with HTTP anymore for local connections. It's a big problem, because Fitbit doesn't have any protocols to talk to native Android apps like Samsung or Android Wear, so the only way to talk is through an HTTP server running by an Android app locally. Implementing HTTPS server on a local device is an overkill and I don't want to do that.
Can you please implement some kind of parameter or exception option that would allow fetch to talk over HTTP? My app is completely useless now because of this issue.
The error is below:
TypeError: Failed to fetch - Please use https:// when communicating with internet endpoints. https://dev.fitbit.com/reference/companion-api/fetch/
In Fetch documentation local HTTP connections are allowed:
Please note: fetch() can only be used to access https endpoints and resources, except when accessing resources on a local network by IP address
So, it's probably a bug. I've tried both "localhost" and "127.0.0.1" with the same result. Yet another interesting thing is that connection is established and if a response doesn't have a body, just a status code, it works. It fails only when a response has a body.
Answered! Go to the Best Answer.
04-26-2019 05:51 - edited 04-26-2019 05:51
04-26-2019 05:51 - edited 04-26-2019 05:51
So I found out what was causing the error for me. The error message is misleading as it states I should be using https, while the real reason is malformed url.
I was sending a get request like this:
http://localhost:1234/command?data=my data
Note the unescaped space in the query string. When I escaped the URL properly using encodeURIComponent, the http fetch came through without issues.
04-26-2019 03:57
04-26-2019 03:57
Hey,
I've run into this as I do use the local HTTP server for communication between companion app and my Android app.
I've noticed that when using HTTP, even though Fitbit complains of HTTP being used and not HTTPS, the request comes through. In addition, the request will result in complain (TypeError: Failed to fetch - Please use https:// when communicating with internet endpoints. https://dev.fitbit.com/reference/companion-api/fetch/) only for the first time, subsequent http fetches will succeed without any complaints whatsoever.
I'm using NanoHTTPD, tried to implement SSL for localhost in there but gave up after X hours wasted, seems to me that Android implementation of the Chromium webview doesn't like SSL on localhost at all.
04-26-2019 04:09 - edited 04-26-2019 04:10
04-26-2019 04:09 - edited 04-26-2019 04:10
[double post]
04-26-2019 05:51 - edited 04-26-2019 05:51
04-26-2019 05:51 - edited 04-26-2019 05:51
So I found out what was causing the error for me. The error message is misleading as it states I should be using https, while the real reason is malformed url.
I was sending a get request like this:
http://localhost:1234/command?data=my data
Note the unescaped space in the query string. When I escaped the URL properly using encodeURIComponent, the http fetch came through without issues.
04-26-2019 08:11
04-26-2019 08:11
Yes, it's correct. I've found out it too lately. I had a space in URL and it worked well in the previous SDK versions, but in 3.0 and in 3.1 it doesn't work anymore and this misleading HTTPS error is served.
Fitbit, please fix the error message and document the fact that you've changed the way how URL is processed in SDK ver 3.
I fixed it in my case by replacing spaces in URL with %20
04-29-2019 00:05
04-29-2019 00:05
Great...I think you should be able to mark either your or mine post as solution. Thanks!
09-03-2019 12:17
09-03-2019 12:17
Hi, it is right that the error is misleading, but i do not think that it has to be a malformed url, it could be to do with the server location. For an app, i was using a local server (with options for the hosting url), while it accepted 192.168.0.xx and 127.0.0.1, it did not like 0.0.0.0, meaning i had to work changing the addresses. Hope this helps anyone else with this problem 🙂
09-03-2019 12:22
09-03-2019 12:22