离子2科尔多瓦http错误

时间:2023-01-31
本文介绍了离子2科尔多瓦http错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我知道这个问题出现了很多次,但我现在已经在网上搜索了大约两天并测试了这么多案例,我认为是时候寻求帮助了.

I know that question came up many times, but I've now seached the web about two days and tested so many cases, that I think it is time to call some help.

我的情况:我有一个 ionic 2 应用程序,它有一个用节点编写的外部 API,并通过 Auth0 和 JWT 进行了身份验证.主要问题是通过 Http 在 android 模拟应用程序中的请求没有调用 API.就像应用程序无法调用自身外部一样.这也适用于共享离子云应用程序.

My Case: I've an ionic 2 application with a external API written in node and authenticated with Auth0 and JWT. The main problem is that the request through Http within an android emulated app is not calling the API. It is like the app can not call outside itself. That came up also for and shared ionic cloud app.

我是如何产生错误的:在所有之前我从cordova安装了白名单插件并允许EVERYTHING(这里是config.xml:https://hastebin.com/fekuvijaxi.xml).我还将 http-equiv 添加到我的 index.html (https://hastebin.com/gocevomayo.xml).现在我已经用cordova ionic cordova run android -lcs 盯着这个应用程序了.我的设备在下面.

How I produce the error: Before all I installed the whitelist plugin from cordova and allowed EVERYTHING (here the config.xml: https://hastebin.com/fekuvijaxi.xml). I have also added the http-equiv to my index.html (https://hastebin.com/gocevomayo.xml). Now I've stared the app with cordova ionic cordova run android -lcs. My device below.

我可以从我的 http 包装器中归档的错误(import { AuthHttp } from 'angular2-jwt';)是:

The error I can archive from my http wrapper (import { AuthHttp } from 'angular2-jwt';) is that:

[14:47:36]  console.log: http://localhost:8080/api/v1/auth/login
[14:47:36]  console.log: {"_body":{"isTrusted":true},"status":0,"ok":false,"statusText":"","headers":{},"type":3,"url":null}

我的服务功能:https://hastebin.com/zudepameca.coffeescript

设备:序列号:emulator-5584鸸鹋版本:26.1.2-4077558Android:7.1(牛轧糖)- API 25

Device: Serial: emulator-5584 Emu Version: 26.1.2-4077558 Android: 7.1 (Nougat) - API 25

离子信息:全局包:

@ionic/cli-utils : 1.5.0
Cordova CLI      : 7.0.1
Ionic CLI        : 3.5.0

本地包:

@ionic/app-scripts              : 2.0.2
@ionic/cli-plugin-cordova       : 1.4.1
@ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms               : android 6.2.3 browser 4.1.0 ios 4.4.0
Ionic Framework                 : ionic-angular 3.5.3

系统:

Node       : v7.8.0
OS         : macOS Sierra
Xcode      : Xcode 8.3.3 Build version 8E3004b
ios-deploy : 1.9.1
ios-sim    : 5.1.0
npm        : 5.3.0

推荐答案

感谢@0mpurdy 和@captain_jim1 有时间帮助我.

Thanks to @0mpurdy and @captain_jim1 for there time to help me.

我是如何解决这个问题的:

How I solved this issue:

起初我确定问题不在服务器端,所以我记录了所有传入的请求.直到我一无所获,我才知道是我的 APP 出了问题.

At first I'd made sure the problem was not on server side, so I logged any incomming requests. Until I got none, I'd know it was something wrong with my APP.

所以在我的应用程序中,我从问题的结尾到开头,从每个功能和可观察到的内容进行记录.我得到了一个错误(上面列出的).所以我在这里和网上搜索了一个解决方案并找到了一个:

So in my APP I logged from the end of the problem to the beginning, from every function and observable. And I got an error (listed above). So I searched here and in the web for a solution and found one:

我只需要添加这一行 <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: * 'unsafe-eval'; style-src'self' 'unsafe-inline'; media-src *"> 进入我的 app/index.hmtl.如此处所述:https://github.com/apache/cordova-插件白名单#content-security-policy

I just had to add this line <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: * 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> into my app/index.hmtl. As descriped here: https://github.com/apache/cordova-plugin-whitelist#content-security-policy

这篇关于离子2科尔多瓦http错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:来自画廊的图像未显示在 ionic 2 的 img 标签上 下一篇:离子构建android,错误:产生EACCES

相关文章

最新文章