Search code examples
androidionic4ionic-nativecapacitor

capacitor ionic android - can't make GET requests to my server - requests are served "from-disk-cache"


When running capacitor for android, GET requests to my API aren't working, and I am getting weird headers (Client-Via:shouldInterceptRequest) as well as the fact that the request is served from disk cache. also the request is having incorrect Content-Type of Content-Type:text/html instead of JSON enter image description here Using capacitor ionic V1.0.0

While running the request from the browser, or capacitor IOS it's working totally fine and the request is being served from the network as well with the correct headers.

Browser response: enter image description here

Any idea of why my webview requests are being intercepted like this? Thanks.


Solution

  • Managed to find the solution, and decided to post the question & answer for others to come across this issue.

    The root cause was that my server URL was also in my capacitor.config.json under the allowNavigation config.

    Thus GET requests were intercepted by capacitor. Removing my server URL from allowNavigation solved the issue. before:

    {
      "appId": "app.com",
      "appName": "app",
      "bundledWebRuntime": false,
      "npmClient": "npm",
      "webDir": "dist",
      "server": {
        "allowNavigation": [
            "my-server-url.com",
          ]
      },
      "android": {
        "allowMixedContent": true
      }
    }
    

    the corrected config:

    {
      "appId": "app.com",
      "appName": "app",
      "bundledWebRuntime": false,
      "npmClient": "npm",
      "webDir": "dist",
      "server": {
        "allowNavigation": []
      },
      "android": {
        "allowMixedContent": true
      }
    }