Ionic CORS issue
I'm facing CORS issue as expected for
1. ionic serve
and
2. ionic cordova run android
3. ionic cordova build android --debug
I resolved the issue for 1. ionic serve
using
- a local proxy in
ionic.config.json
as per this blog https://blog.ionicframework.com/handling-cors-issues-in-ionic/
"proxies": [
{
"path": "/proxy",
"proxyUrl": "https://xx.xx.xx/"
}
]
- set the Access-Control-Allow-Origin header in my POST calls like:
>
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',
})
};
But using 2. ionic cordova run android
and 3. ionic cordova build android --debug
I still have the below error:
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)
The blog also mentions that when creating an APK cors won't be an issue. But if I remove the proxy and make an APK using 3. ionic cordova build android --debug
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
Cors issue appears. Why does it occur for APKs for me? Shouldn't on device use the resources from file:// and not the localhost:// and thus avoid CORS issue?
And how do I
a. fix the cors error
or
b. make the proxy work for APK builds.
Oddly the server reply has Access-Control-Allow-Origin
Server →nginx/1.10.3 (Ubuntu)
Date →Thu, 03 Jan 2019 14:25:23 GMT
Content-Type →application/json
Content-Length →1010
Connection →keep-alive
Access-Control-Allow-Origin →*
Access-Control-Allow-Methods →POST
ionic version: 4.5.0
OS: Mac OSX Mojave
platform: Android
angular ionic-framework cors ionic3
|
show 10 more comments
I'm facing CORS issue as expected for
1. ionic serve
and
2. ionic cordova run android
3. ionic cordova build android --debug
I resolved the issue for 1. ionic serve
using
- a local proxy in
ionic.config.json
as per this blog https://blog.ionicframework.com/handling-cors-issues-in-ionic/
"proxies": [
{
"path": "/proxy",
"proxyUrl": "https://xx.xx.xx/"
}
]
- set the Access-Control-Allow-Origin header in my POST calls like:
>
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',
})
};
But using 2. ionic cordova run android
and 3. ionic cordova build android --debug
I still have the below error:
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)
The blog also mentions that when creating an APK cors won't be an issue. But if I remove the proxy and make an APK using 3. ionic cordova build android --debug
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
Cors issue appears. Why does it occur for APKs for me? Shouldn't on device use the resources from file:// and not the localhost:// and thus avoid CORS issue?
And how do I
a. fix the cors error
or
b. make the proxy work for APK builds.
Oddly the server reply has Access-Control-Allow-Origin
Server →nginx/1.10.3 (Ubuntu)
Date →Thu, 03 Jan 2019 14:25:23 GMT
Content-Type →application/json
Content-Length →1010
Connection →keep-alive
Access-Control-Allow-Origin →*
Access-Control-Allow-Methods →POST
ionic version: 4.5.0
OS: Mac OSX Mojave
platform: Android
angular ionic-framework cors ionic3
1
You need to have access to your Login Server. There you need to set up CORS and you need to set there the Allowed Origins
– Jonathan
Jan 3 at 8:05
The web service is from a 3rd party. Can this be handled from our side ?
– ir2pid
Jan 3 at 8:09
There is an website called "AllowCorsEverywhere" this could help you. The next reason for this cors error is that you do your request via http on localhost. And maybe the security settings on the login server dont accept http requests. only https requests
– Jonathan
Jan 3 at 8:13
1
btw did you set a Access-Control-Allow-Origin header at your request?
– Jonathan
Jan 3 at 8:20
1
Access-Control-Allow-*
are response headers, not request headers. They do no belong on your request options at all! Since you are using a proxy, they shouldn't even be needed on the response. You must have misconfigured the proxy.
– Quentin
Jan 7 at 9:38
|
show 10 more comments
I'm facing CORS issue as expected for
1. ionic serve
and
2. ionic cordova run android
3. ionic cordova build android --debug
I resolved the issue for 1. ionic serve
using
- a local proxy in
ionic.config.json
as per this blog https://blog.ionicframework.com/handling-cors-issues-in-ionic/
"proxies": [
{
"path": "/proxy",
"proxyUrl": "https://xx.xx.xx/"
}
]
- set the Access-Control-Allow-Origin header in my POST calls like:
>
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',
})
};
But using 2. ionic cordova run android
and 3. ionic cordova build android --debug
I still have the below error:
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)
The blog also mentions that when creating an APK cors won't be an issue. But if I remove the proxy and make an APK using 3. ionic cordova build android --debug
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
Cors issue appears. Why does it occur for APKs for me? Shouldn't on device use the resources from file:// and not the localhost:// and thus avoid CORS issue?
And how do I
a. fix the cors error
or
b. make the proxy work for APK builds.
Oddly the server reply has Access-Control-Allow-Origin
Server →nginx/1.10.3 (Ubuntu)
Date →Thu, 03 Jan 2019 14:25:23 GMT
Content-Type →application/json
Content-Length →1010
Connection →keep-alive
Access-Control-Allow-Origin →*
Access-Control-Allow-Methods →POST
ionic version: 4.5.0
OS: Mac OSX Mojave
platform: Android
angular ionic-framework cors ionic3
I'm facing CORS issue as expected for
1. ionic serve
and
2. ionic cordova run android
3. ionic cordova build android --debug
I resolved the issue for 1. ionic serve
using
- a local proxy in
ionic.config.json
as per this blog https://blog.ionicframework.com/handling-cors-issues-in-ionic/
"proxies": [
{
"path": "/proxy",
"proxyUrl": "https://xx.xx.xx/"
}
]
- set the Access-Control-Allow-Origin header in my POST calls like:
>
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',
})
};
But using 2. ionic cordova run android
and 3. ionic cordova build android --debug
I still have the below error:
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)
The blog also mentions that when creating an APK cors won't be an issue. But if I remove the proxy and make an APK using 3. ionic cordova build android --debug
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
Cors issue appears. Why does it occur for APKs for me? Shouldn't on device use the resources from file:// and not the localhost:// and thus avoid CORS issue?
And how do I
a. fix the cors error
or
b. make the proxy work for APK builds.
Oddly the server reply has Access-Control-Allow-Origin
Server →nginx/1.10.3 (Ubuntu)
Date →Thu, 03 Jan 2019 14:25:23 GMT
Content-Type →application/json
Content-Length →1010
Connection →keep-alive
Access-Control-Allow-Origin →*
Access-Control-Allow-Methods →POST
ionic version: 4.5.0
OS: Mac OSX Mojave
platform: Android
angular ionic-framework cors ionic3
angular ionic-framework cors ionic3
edited Feb 15 at 6:23
OneLunch Man
1,355319
1,355319
asked Jan 3 at 7:54
ir2pidir2pid
1,11411639
1,11411639
1
You need to have access to your Login Server. There you need to set up CORS and you need to set there the Allowed Origins
– Jonathan
Jan 3 at 8:05
The web service is from a 3rd party. Can this be handled from our side ?
– ir2pid
Jan 3 at 8:09
There is an website called "AllowCorsEverywhere" this could help you. The next reason for this cors error is that you do your request via http on localhost. And maybe the security settings on the login server dont accept http requests. only https requests
– Jonathan
Jan 3 at 8:13
1
btw did you set a Access-Control-Allow-Origin header at your request?
– Jonathan
Jan 3 at 8:20
1
Access-Control-Allow-*
are response headers, not request headers. They do no belong on your request options at all! Since you are using a proxy, they shouldn't even be needed on the response. You must have misconfigured the proxy.
– Quentin
Jan 7 at 9:38
|
show 10 more comments
1
You need to have access to your Login Server. There you need to set up CORS and you need to set there the Allowed Origins
– Jonathan
Jan 3 at 8:05
The web service is from a 3rd party. Can this be handled from our side ?
– ir2pid
Jan 3 at 8:09
There is an website called "AllowCorsEverywhere" this could help you. The next reason for this cors error is that you do your request via http on localhost. And maybe the security settings on the login server dont accept http requests. only https requests
– Jonathan
Jan 3 at 8:13
1
btw did you set a Access-Control-Allow-Origin header at your request?
– Jonathan
Jan 3 at 8:20
1
Access-Control-Allow-*
are response headers, not request headers. They do no belong on your request options at all! Since you are using a proxy, they shouldn't even be needed on the response. You must have misconfigured the proxy.
– Quentin
Jan 7 at 9:38
1
1
You need to have access to your Login Server. There you need to set up CORS and you need to set there the Allowed Origins
– Jonathan
Jan 3 at 8:05
You need to have access to your Login Server. There you need to set up CORS and you need to set there the Allowed Origins
– Jonathan
Jan 3 at 8:05
The web service is from a 3rd party. Can this be handled from our side ?
– ir2pid
Jan 3 at 8:09
The web service is from a 3rd party. Can this be handled from our side ?
– ir2pid
Jan 3 at 8:09
There is an website called "AllowCorsEverywhere" this could help you. The next reason for this cors error is that you do your request via http on localhost. And maybe the security settings on the login server dont accept http requests. only https requests
– Jonathan
Jan 3 at 8:13
There is an website called "AllowCorsEverywhere" this could help you. The next reason for this cors error is that you do your request via http on localhost. And maybe the security settings on the login server dont accept http requests. only https requests
– Jonathan
Jan 3 at 8:13
1
1
btw did you set a Access-Control-Allow-Origin header at your request?
– Jonathan
Jan 3 at 8:20
btw did you set a Access-Control-Allow-Origin header at your request?
– Jonathan
Jan 3 at 8:20
1
1
Access-Control-Allow-*
are response headers, not request headers. They do no belong on your request options at all! Since you are using a proxy, they shouldn't even be needed on the response. You must have misconfigured the proxy.– Quentin
Jan 7 at 9:38
Access-Control-Allow-*
are response headers, not request headers. They do no belong on your request options at all! Since you are using a proxy, they shouldn't even be needed on the response. You must have misconfigured the proxy.– Quentin
Jan 7 at 9:38
|
show 10 more comments
1 Answer
1
active
oldest
votes
You will always have CORS issues on WKWebview if you can't change the Server Settings, you can't do this by client. Suggestion, change to ionic native http
https://ionicframework.com/docs/v3/native/http/
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018339%2fionic-cors-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You will always have CORS issues on WKWebview if you can't change the Server Settings, you can't do this by client. Suggestion, change to ionic native http
https://ionicframework.com/docs/v3/native/http/
add a comment |
You will always have CORS issues on WKWebview if you can't change the Server Settings, you can't do this by client. Suggestion, change to ionic native http
https://ionicframework.com/docs/v3/native/http/
add a comment |
You will always have CORS issues on WKWebview if you can't change the Server Settings, you can't do this by client. Suggestion, change to ionic native http
https://ionicframework.com/docs/v3/native/http/
You will always have CORS issues on WKWebview if you can't change the Server Settings, you can't do this by client. Suggestion, change to ionic native http
https://ionicframework.com/docs/v3/native/http/
answered Feb 3 at 16:08
RyuRyu
84
84
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018339%2fionic-cors-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You need to have access to your Login Server. There you need to set up CORS and you need to set there the Allowed Origins
– Jonathan
Jan 3 at 8:05
The web service is from a 3rd party. Can this be handled from our side ?
– ir2pid
Jan 3 at 8:09
There is an website called "AllowCorsEverywhere" this could help you. The next reason for this cors error is that you do your request via http on localhost. And maybe the security settings on the login server dont accept http requests. only https requests
– Jonathan
Jan 3 at 8:13
1
btw did you set a Access-Control-Allow-Origin header at your request?
– Jonathan
Jan 3 at 8:20
1
Access-Control-Allow-*
are response headers, not request headers. They do no belong on your request options at all! Since you are using a proxy, they shouldn't even be needed on the response. You must have misconfigured the proxy.– Quentin
Jan 7 at 9:38