2

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.

6
  • are you testing the cordova application on your mobile device ?
    – OmG3r
    Commented Jan 23, 2021 at 20:41
  • @OmG3r Tried it both on emulator and on my device. Got the same result :/
    – DrBenana
    Commented Jan 23, 2021 at 21:02
  • try replacing 'localhost' with your local IP address 192.168.1.x (you need to replace x), you can find it using 'ipconfig' for windows, and 'ifconfig' for linux
    – OmG3r
    Commented Jan 23, 2021 at 21:51
  • Maybe add for what version and platform, that would help
    – Eric
    Commented Jan 23, 2021 at 22:11
  • @OmG3r Tried it, Still not working. I've even tried it on an external device and same.
    – DrBenana
    Commented Jan 24, 2021 at 6:51

1 Answer 1

2

I've found a solution. If someone comes here after non-stop google search, here it is: Failed to load resource: net::ERR_CLEARTEXT_NOT_PERMITTED

1
  • Adding the permissions and application note did work for me as well. I had internet permission already.
    – Chris
    Commented Aug 19, 2022 at 16:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.