// This is the standard http/post function used systemwide
post(endpoint, payload, add_device_infos=false):Promise<any>{
//create a unique hash for every request that comes in and save it in an array with its counter at value 1
let requestHash=this.getHash();
this.requests[requestHash]=1;
//send the request
return new Promise((resolve, reject) => {
this.http.post(this.config.api_url+''+endpoint,payload,{}).map(res => res.json()).subscribe(data => {
//request successfull, resolve the promise
resolve(data);
err => {
//Request fails, so i handle the failure
this.postFailure(endpoint, payload, requestHash, resolve, reject);
//handle the failure
postFailure(endpoint, payload, requestHash, resolve, reject){
//if the request hash doesnt exist or the counter for this request hash reached 5, i stop trying and accept, that the request failed for good
if(!this.requests[requestHash] || this.requests[requestHash]>=5){
delete this.requests[requestHash];
this.loader.stopLoading();
this.toaster.present(this.getTranslation('connection_error'));
reject({});
return;
//Increase the counter for this request hash and try again
this.requests[requestHash]++;
this.http.post(this.config.api_url+''+endpoint,payload,{}).map(res => res.json()).subscribe(data => {
//request successfull, resolve the promise
resolve(data);
err => {
//Request fails, so i handle the failure
this.postFailure(endpoint, payload, requestHash, resolve, reject);
It will be a CORS issue - look at the headers for the requests - the server needs to allow certain headers, also note that there is a preflight request - see the OPTIONS request
See: http://ionicframework.com/docs/wkwebview/#cors
Also see: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
But if it is a CORS issue, it wouldnt work at all. But it works flawless on Android and the browser.
And on iOS it sometimes works on the first try and sometimes on the third try (same request).
So i dont see, why this is a CORS issue…
But if you could convince me, i would be more then happy to have at least any clue
In Ionic 3 iOS uses WKWebView which means that CORS is now mandatory - Android doesn’t use CORS, neither does the desktop browser
See: http://ionicframework.com/docs/wkwebview/#cors
WKWebview was definitely the right way to go with Ionic 3 (although more difficult to use because of CORS) as Apple recommend that you don’t use the older UIWebView which was used in Ionic 1 - see: https://developer.apple.com/documentation/webkit/wkwebview
let headers: any = new Headers({
‘Content-Type’: ‘application/json’,
‘Access-Control-Allow-Origin’: ‘’,
‘Access-Control-Allow-Headers’: '’,
‘Access-Control-Allow-Methods’: ‘*’
let options = { headers: headers };
this.http.post(link, myData, options)
.subscribe(data => {
}, err => {
this.loading.dismiss();
console.log(err);
alert(err);
still I’m facing issue in above code…please help me out from this… Thanks in advance… In android its working fine but in iOS(11.4) I’m facing
“Response with status: 0 for URL: null” issue.
Hello Skee,
I have same issue in android, rest api not working in android emulator or device and give error: Response with 0 for Url: null.
and finally i got solution that there is cordova platform android version issue, if there is cordova Android version is 6.3 then it’s working properly but it there is cordova Android version is 7.0 or 7.1.1 then it’s not working for me.
So, I think in ios you should check your ios platform version and then try again.
You can check ios or android version using cli command.
ionic info
Also check your all cordova plugins is installed or not. If someone is missing then install it manually and check again.
You can check your cordova plugins using cli command.
cordova plugin -ls
I think it is helpful you.
Thanks
Hi EveryOne I have found the best possible solution for WKWebView and it works fine
This issue happened due to the WKWebView Mostly in IONIC 3
So, the very simple way to use the WKWebView in Ionic is that You Must uninstall the previously installed UIWebView from the plugin by running the following command.
ionic cordova plugin remove cordova-plugin-ionic-webview
After that try to add the WKWebView Plugin with this command
ionic cordova plugin add cordova-plugin-wkwebview-engine
When the WkWebView plugin is installed the very next thing is to add the following lines in the config.xml file
feature name=“CDVWKWebViewEngine”
param name=“ios-package” value=“CDVWKWebViewEngine”
feature
preference name=“CordovaWebViewEngine” value=“CDVWKWebViewEngine”
preference name=“WKWebViewOnly” value=“true”
After doing all that when you try to run the application and hit some api call you will get the preflight issue in that due to CORS so to fix that. Simply run the following command
ionic cordova plugin add cordova-plugin-wkwebviewxhrfix
After adding the above plugin the CORS issue will be resolved
Thanks,
Happy Coding
Thankyou for the help.
Precisely we need to add this to config.xml under ios section
<platform name="ios">
<preference name="WKWebViewOnly" value="true" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
</platform>