I have an express server which has an API endpoint of /todo/set which gets a JSON, POST request.
This API uses cors.
Additionally, I have a Cordova android application (which built with Svelte) and I'm trying to make a request via fetch to the express server. This is what the request looks like:
fetch(`http://localhost:8080/todo/set`, {
method: "post",
body: JSON.stringify({
'Text': 'Test!'
}),
headers: {
'Content-Type': 'application/json',
}
})
This isn't working, the server is not getting the request. So I've tried to debug it a little and did this:
fetch(`http://localhost:8080/todo/set`, {
method: "post",
body: JSON.stringify({
'Text': 'Test!'
}),
headers: {
'Content-Type': 'application/json',
}
}).then(res => alert(res)).catch(err => alert(err))
After running it I've got "TypeError: Failed to fetch" on the alert. So I've tried it once again, This time checked it outside of the Cordova (Only Svelte on a website). This time it's all worked and I got status 200 from the server.
- It's also tested with Postman and it's working as expected
So I understood that the issue is related to Cordova, But I can't find why it happends. Does someone know how I can solve it?
An update: Tried to add a browser platform to Cordova and tried there. It's working on the browser.
question from:
https://stackoverflow.com/questions/65864040/typeerror-failed-to-fetch-only-on-cordova-application 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…