Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fetch doesn't support HTTP anymore

ANSWERED

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.

Best Answer
1 BEST ANSWER

Accepted Solutions

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.

View best answer in original post

Best Answer
7 REPLIES 7

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.

Best Answer
0 Votes

[double post]

Best Answer
0 Votes

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.

Best Answer

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

Best Answer
0 Votes

Great...I think you should be able to mark either your or mine post as solution. Thanks!

Best Answer
0 Votes

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 🙂

Best Answer
In my case, it was definitely a malformed URL - there was a space in it.
After changing it to %20, it started working again
Best Answer
0 Votes