离子+角 - 如何避免" 404未找​​到(从高速缓存)QUOT;后POST请求? [英] Ionic + Angular - How to avoid the "404 Not Found (from cache)" after POST request?

查看:209
本文介绍了离子+角 - 如何避免" 404未找​​到(从高速缓存)QUOT;后POST请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是部分指着我的previous问题:
离子+角POST请求返回状态404

this question is partly pointing to my previous question : Ionic + Angular POST request return state 404

但我没能找到工作的解决方案。

But i wasn't able to find working solution.

问题在于以下几点:

如果我从移动应用的设备我总是得到响应404上运行的要求做的:

if I do request from the mobile app running on the device i always get response 404:

Request Method:POST
Status Code:404 Not Found (from cache)
Request Headersview source
Accept:application/json, text/plain, */*
Content-Type:text/plain
Origin:file://
User-Agent:Mozilla/5.0 (Linux; Android 4.4.2; Lenovo Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
Request Payloadview source
{,…}

但是,如果我在Chrome浏览器尝试使用邮差插件在桌面上了同样的要求,我总是得到响应200正是我需要的数据。

But if i tried the same request on the desktop using Postman plugin in the Chrome browser i always get response 200 with data what i need.

我认为这是由角HTTP方法,但在previous后问题引起我被发现,事实并非如此。

I thought that it was issue caused by Angular http method but in previous post i was noticed that is not true.

我怎样才能避免这种情况吗?我应该在请求期间或者在服务器端(PHP)设置一些头在应用程序的HTML,?

How can i avoid this please? Should i set some headers in HTML of the app, during the request or on the server side (PHP)?

任何意见非常感谢。

编辑:

我想还设置缓存:通过这样的方式虚假的:

I tried also set cache:false by this way:

$http({
                method : 'POST',
                url : $scope.remoteUrl,
                data: postData,
                headers: headersData,
                cache: false,
                timeout: 10000
                // success response
            })

但是,如果没有运气。

But without luck.

推荐答案

A <一个href=\"http://stackoverflow.com/questions/30124099/ionic-leaflet-cant-get-tiles-404-not-found-from-cache/30128353\">lot人是<一个href=\"http://stackoverflow.com/questions/30122890/ionic-angular-post-request-return-state-404/30209484#30209484\">experiencing这。

我只是碰到了同样的问题。这似乎它与科尔多瓦的新版本新的安全策略做。

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

下面是我如何解决它:

我安装科尔多瓦的白名单插件

cordova plugin add cordova-plugin-whitelist

然后,添加内容政策在 index.html的作为元标签(使用您自己的主机或*接受所有请求):

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';">

默认的s​​rc 用于一般要求;在 WS://本地主机:35729 主机被用于实时重载的离子服务

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

脚本的src 用于安全执行脚本

不安全的内联不安全-EVAL 要求,以便角正常工作。

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

数据:差距:https://ssl.gstatic.com 只用在iOS

表示的当前主机的index.html 文件。

您必须添加自己为了您的要求工作。不要忘了,如果他们是非标准添加协议和端口号

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

您可以跳过meta标签,如果你不想要它,但你会从白名单中的插件得到很多的警告。

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

如何在插件的自述。

然后重建您的应用程序,它应该工作了。

Then rebuild your app, and it should work again.

这篇关于离子+角 - 如何避免&QUOT; 404未找​​到(从高速缓存)QUOT;后POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆