我刚刚更新上的角+离子和处理远程请求新版本的方法停止工作并返回总是404的响应。
I just updated on the new version on the Angular + Ionic and method for processing remote request stopped working and returns always 404 response.
请求是以下内容:
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
{,…}
这是处理远程请求的方法的 code是如下:
// set transfer credentials
$http({
method : 'POST',
url : $scope.remoteUrl,
data: {img_base64: "/9j/4AAQSkZ"},
headers: 'application/json',
timeout: 10000
// success response
}).success(function(data, status, headers, config) {
//SUCESSS
} else {
//PROCESSING ERROR
}
// error response
}).error(function(data, status, headers, config) {
// ERROR
});
我试图用这个话题来解决这个问题:
I tried to solve it using this topic:
AngularJs $ http.post()不发送数据
和
Angular +离子Post请求获得404找不到
但没有运气。
服务器端的处理由这样的请求:
$inputJSON = file_get_contents('php://input');
$input= json_decode( $inputJSON, TRUE ); //convert JSON into array
如果我试图用邮差发送请求或卷曲的一切似乎是工作。
If i'm trying to send request using Postman or Curl everything seems to be working.
离子信息:
Node Version: v0.12.2
Cordova CLI: 5.0.0
Ionic CLI Version: 1.3.22
Xcode version: Xcode 6.3.1 Build version 6D1002
ios-sim version: Not installed
ios-deploy version: Not installed
AngularJS版本:
AngularJS version:
"version": "1.3.13",
我怎么能解决这个问题吗?
How can i solve it please?
非常感谢任何意见
推荐答案
呜呜,我只是碰到了同样的问题:标题表明它已经被抓走从缓存
。 ..但实际上,现在看来,这是同科尔多瓦的新版本,新的安全策略。
Hum, I just ran into the same problem: the header suggests it has been fetched from cache
... But actually, 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';">
默认-SRC
用于一般要求;在 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.
相关推荐
最新文章