Hi,
TypeError: failed to fetch from Fitbit Ionic over port 443 (but works with port 80), which I setting up API server with nginx and self-signed certificate and I works fine when testing from others with postman to GET/POST over port 80 and 443
How can i fix fetch with self-sign? may i guess it cause of certification verify during fetch.
Mobile OS: iOS
Permission Grant: "access_internet",
Error message: TypeError: Failed to fetch
Example Code:
fetch(`https://192.168.1.100/api/v1/test`, {
method: "POST",
body: `data=test-sent-over-https`,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "asdlkfjapoifhsld'alsjdk;fasakfd"
}
})
.then((res) => {
return res.json()
.then((res) => {
console.log(`response: ${JSON.stringify(res)}`);
});
})
.catch((err)=>{
console.log(err);
});
I just found below topic but i not sure my problem is the same thing:-
Best AnswerI've spent many hours trying to get companion fetch() to accept a self-signed certificate, but have failed. The certificate works fine via a browser, but that's probably because the browser can set a security exception.
Best AnswerHi,
Today i just go back to read Fetch API documents of Fitbit again, I not sure when below description added to the page, but it think it related with my problem:-
fetch()
This API is used to GET and POST across a network.
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, that my problem cause of Fitbit fetch cannot accessing to local network by IP address.
Best AnswerYou're right. But I can't get fetch to work with http on a LAN server accessed via IP. I wonder if it may be limited to specific IPs and/or ports (which may have the side-effect of limiting it to localhost).
Best AnswerFurther to the theory about specific IPs, see this.
I think I've reached the conclusion that fetch over LAN requires https with a not-self-signed certificate.
Best Answer