Ionic + Angular - How to avoid the “404 Not Found (from cache)” after POST request?

孤街醉人 提交于 2019-12-02 18:57:20
Tiesselune

A lot of people are experiencing that.

I just ran into the same problem. It seems it has to do with a new security policy in new versions of Cordova.

Here's how I solved it:

I installed Cordova's whitelist plugin :

cordova plugin add cordova-plugin-whitelist

Then, add your content policy in your index.html as a meta tag (using your own host or '*' for accepting all requests) :

<meta http-equiv="Content-Security-Policy" content="default-src 'self' yourhost.com ws://localhost:35729 data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *;script-src 'self' localhost:35729 'unsafe-eval' 'unsafe-inline';">

default-src is used for general requests; the ws://localhost:35729 host is used for live-reload in ionic serve.

script-src is used for secure script execution

unsafe-inline and unsafe-eval are required in order for angular to work properly.

data: gap: https://ssl.gstatic.com is only used on iOS.

self means the current host of the index.html file.

You'll have to add your own in order for your requests to work. Don't forget to add the protocol and the port if they're non-standard

You can skip the meta tag if you don't want it, but you'll get a lot of warnings from the whitelist plugin.

More info on how to configure this in the plugin's readme.

Then rebuild your app, and it should work again.

Bruno Samardžić

Had a same problem, nothing helped, then i just removed the whitelist plugin:

cordova plugin remove cordova-plugin-whitelist

then renstalled it

cordova plugin add cordova-plugin-whitelist

then it worked

I had the same problem and I could solve it by adding the following plugin:

ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git

After many hours, I found one solution that worked: run cordova plugin add cordova-plugin-whitelist

In my case, I had already configured config.xml and index.html on origin, as mentioned here and elsewhere.

Suhas s

I had a similar issue with Firebase sign on my android device but I could login on the browser.

cordova plugin remove cordova-plugin-whitelist
cordova plugin add cordova-plugin-whitelist

Used the above lines to resolve the issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!