我正面临预期的CORS问题
text
和1. ionic serve
2. ionic cordova run android
我使用
解决了3. ionic cordova build android --debug
的问题
1. ionic serve
中的本地代理as per this blog https://blog.ionicframework.com/handling-cors-issues-in-ionic/
ionic.config.json
>
"proxies": [
{
"path": "/proxy",
"proxyUrl": "https://xx.xx.xx/"
}
]
但是使用reqOpts = {
headers: new HttpHeaders({
'Content-Type':'application/json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'POST, GET, PUT, OPTIONS, DELETE, PATCH',
'Accept':'application/json',
})
};
和2. ionic cordova run android
仍然出现以下错误:
3. ionic cordova build android --debug
博客还提到在创建APK核心时不会出现问题。但是,如果我删除代理并使用01-02 15:49:48.815 3682-3889/com.xx.xx D/SERVER: Handling local request: http://localhost:8080/proxy/xx/login
01-02 15:49:48.859 3682-3682/com.xx.xx D/SystemWebChromeClient: http://localhost:8080/build/main.js: Line 834 : [object Object]
01-02 15:49:48.859 3682-3682/com.xx.xx I/chromium: [INFO:CONSOLE(834)] "[object Object]", source: http://localhost:8080/build/main.js (834)
01-02 15:49:48.863 3682-3682/com.xx.xx D/SystemWebChromeClient: http://localhost:8080/build/vendor.js: Line 1823 : ERROR
01-02 15:49:48.864 3682-3682/com.xx.xx I/chromium: [INFO:CONSOLE(1823)] "ERROR", source: http://localhost:8080/build/vendor.js (1823)
3. ionic cordova build android --debug
Cors问题出现。为什么我的APK会发生这种情况?在设备上不应该使用来自file://而不是localhost://的资源,从而避免CORS问题吗?
我怎么办
a。修复cors错误
或
b。使代理可用于APK构建。
奇怪的是,服务器回复具有Access-Control-Allow-Origin
Access to XMLHttpRequest at 'https://xx.xx.xx/xx/login'
from origin 'http://localhost:8080' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource. main.js:835
离子版本:4.5.0
OS:Mac OSX Mojave
平台:Android
答案 0 :(得分:0)
如果您无法更改服务器设置,则无法在客户端上执行WKWebview上的CORS问题。建议,更改为离子本机http