BenTimor opened a new issue #267:
URL: https://github.com/apache/cordova/issues/267


   # Support / Bug Report
   
   ## Problem
   
   I have an express server which has an API endpoint of /todo/set which gets a 
JSON, POST request. This API uses cors.
   
   The API's working, it's tested with Postman (On same computer and on another 
computer on same LAN) and it's working with fetch (JavaScript) when using a 
browser (both on phone and computer). Tried to check it both with only running 
Svelte server and using cordova browser platform.
   
   The problem is, When using Cordova android application, the fetch is 
returning "TypeError: Failed to fetch" and the server is not getting the 
request.
   
   This is the code for example:
   ```
   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))
   ```
   
   * Tried to replace the "localhost" with my local IP. Same issue. 
   * The code is the same for the phone application and the website, I'm just 
running it differently (`cordova run android` vs `cordova run browser`).
   
   ### What is expected to happen?
   The server had to get the request at least.
   
   ### What does actually happen?
   Throwing an error and the server is not getting any request.
   
   ## Information
   Posted it also on StackOverflow, Maybe it's a little more clear there: 
https://stackoverflow.com/questions/65864040/typeerror-failed-to-fetch-only-on-cordova-application
   
   ### Reproduce
   - Create a local express server and try to fetch json data from it via 
Cordova android applicatoin. 
   
   ### Environment, Platform, Device
   - Developing on Arch Linux.
   - The application is for android phone, Samsung Note 9 specifically
   
   ### Version information
   - Using Svelte for Frontend 3.0.0
   - Cordova 10.0.0
   I'm using a clone of this repository for the application development: 
https://github.com/BenTimor/SvelteCordova
   
   ## Checklist
   - [X] I searched for existing GitHub issues
   - [X] I updated all Cordova tooling to most recent version
   - [X] I included all the necessary information above
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to