XMLHttpRequest 无法在 Ionic 登录到 odoo 服务器时加载 http://localhost:80

XMLHttpRequest cannot load http://localhost:8088/web/webclient/version_info error in ionic login to odoo server

本文关键字:加载 http 服务器 localhost odoo Ionic 登录 XMLHttpRequest      更新时间:2023-09-26

当我尝试使用离子应用程序登录到odoo服务器时。我得到了下面引用的错误。如果是因为 CORS,如何在不使用 nginx 的情况下在本地 odoo 服务器中进行配置?

XMLHttpRequest cannot load http://localhost:8088/web/webclient/version_info. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

默认情况下,出于安全原因,浏览器会阻止跨域请求,但我们可以通过以下方式实现跨域请求工作。

打开Chrome并安装此插件并在其上,然后尝试发送请求它将起作用,但这不是一个好主意。

https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-ntp-icon

第二个想法

最好的办法是转到中间件并将标头添加为

"访问控制允许来源:*"

它将允许来自不同域的所有请求。

对于节点 Js

res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);

添加科尔多瓦白名单插件

cordova plugin add cordova-plugin-whitelist

做好准备

cordova prepare

将以下行添加到配置中.xml

 <access origin="*"/>
  <allow-intent href="*"/>
  <allow-navigation href="http://*/*" />

对于浏览器的 CORS,请按 cmd 或终端打开镶边。

对于窗户,

C:'Program Files (x86)'Google'Chrome'Application'chrome.exe" --disable-web-security --user-agent="Android" --user-data-dir="C:/temp-chrome-eng

对于 mac-osx,

open -a Google' Chrome --args --disable-web-security --user-data-dir="/Users/thantshweaung/Documents/Project/ionic/chrome_cache" 

解决!

使用您的 IP 地址而不是 localhost 。例如:

http://192._._._:8088/web/webclient/version_info