gpt4 book ai didi

android - IONIC/angular 将原点作为文件 ://in POST and PUT -Getting 403 forbidden Error from API 发送

转载 作者:行者123 更新时间:2023-11-30 00:13:36 24 4
gpt4 key购买 nike

我正在开发 IONIC 3/Angular android 应用程序。对于 Http 调用的 POST 和 PUT 方法,ionic 正在将 http header 源作为 file://发送。它不会将来源添加到 GET 方法。

我使用的库是“@angular/http”。

我们在 API 方面有严格的限制。我们不能修改它。

谁能提出解决方案?

以下是http header的 fragment

    content-type:application/json
Host:XXXXXXX
Origin:file://
User-Agent:Mozilla/5.0 (Linux; Android 7.1.1; Android SDK built
for x86 Build/NYC; wv) AppleWebKit/537.36 (KHTML, like Gecko)
Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:XXXXX
X-Requested-With:com.X.X.X

我还查看了以下帖子和论坛。运气不好

https://forum.ionicframework.com/t/native-app-is-sending-header-origin-file-which-causes-problems/62388

SO 链接但没有解决方案。

Ionic native app is sending header Origin:file:// which causes problems

最佳答案

我不确定这是否能解决您的问题,但我记得前一段时间我在制作 ionic 应用程序时遇到过这个问题。查看我的应用程序设置方式,看起来我使用代理在本地进行 http 调用。我在根目录中有一个名为 ionic.config.json 的文件,如下所示:

{
"name": "mobile",
"app_id": "",
"type": "ionic-angular",
"proxies": [
{
"path": "/api",
"proxyUrl": "http://your-local-api-address"
}
]
}

然后在我用来存储 API 信息的文件中,我将我的 URL 设置为“/api”。肯定有一个解决方案,但可能是您正在尝试做一些 ionic 不能(很容易?)做的事情.. 比如在您尝试在 native 设备上运行应用程序时运行实时重新加载。

更新

基本上是我上面写的,但是发现这个旧帖子来自一个说他有解决方法的人,这是他的输入

I managed to find a working solution ! You need to proxy your api server into livereload so that your web app will think the api server is actually the same as your livereload server. Proxy configuration specs are here : https://github.com/driftyco/ionic- cli#advanced-serve-options For example, if your api server is on 192.168.0.1:8888, you need to add this to your ionic.project :

"proxies": [
{
"path": "/api",
"proxyUrl": "http://192.168.0.1:8888/api"
}
]

And then, inside your app, you have to make your api calls like if it was local, directly from /api.

这是旧帖的链接

https://github.com/ionic-team/ionic-cli/issues/89

关于android - IONIC/angular 将原点作为文件 ://in POST and PUT -Getting 403 forbidden Error from API 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47723492/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com