添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

We do a simple GET over angulars HTTP library to an url like https://smart.blabla.com .
If we run this with ionic serve every thing is fine, but if we run this with ionic cordova emulate android we get a strange error. We tried also to run this on a new clean ionic project, we have the same error.

We test it to make a plain XHR call, and there we get also errors. This is an example of our call:
var xhr = new XMLHttpRequest(); xhr.open('POST', 'https://smart.blabla.com', true); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { console.log(xhr.responseText) } }; xhr.withCredentials = true; xhr.send('{}');

The only thing a new about this error, the POST is never send, the error is on client side. And as mentioned before if I do the same thing in ionic serve anything is working fine.

in my config.xml the access origin is configured like this
<access origin="*" />

Some ideas?

image.png 1902×414 65.8 KB

Edit:
We found out, this is also working on ionic cordova run , so probably in the last few day we tested this only on device and not on emulator . So the question is, why this is working on device and on ionic serve but not on emulator ?

Hmm this remembers me a problem I had two years before with Ionic 1. I resolved the problem when I added this lines to my config.xml

<access origin="*" />
<access origin="http://*" />
<access origin="https://*" />

… or simmilar. I had to explicitly enable usage of http and https protocolls (allthough the file protocoll, tel protocoll, any one I used in the app). Perhaps this could help …

You could allthough have a look at this: <access origin="tel:*" launch-external="yes" /> not worked IOS

access origin or allow-intent? The second one is allready there

<content src="index.html" />
<access origin="*" />
<allow-navigation href="http://ionic.local/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

The strange thing anything was working fine until this morning, the first thing I thought I did something wrong today. But this is also not working anymore on a clean project so :expressionless:

As expected the workaround with the the access origin to http and https doesn’t work.

I found out, If we run it on device there is no error and anything is working fine.

So the problem is only on emulator and probably in the last few days we test this only on device and not emulator.

So the question is why this is working on ionic serve and ionic cordova run but not emulate?

Could be the problem setted firewall rules? Do you have root access and setted ip tables on your emulated device? Perhaps there are optional ways with adb to set routes to your network. Did you allthough looked for your proxies you are able to set in Ionic1 projects?

I never used the emulater. And I don’t know if you are able to set proxies on Ionic2 projects … I just had this thoughts about your issue …

If solve it, let us know :slight_smile: Sorry for poor English.

Edit: OMG!!!

I found the solution, I had the problem because the emulator was offline!!! :expressionless:

Offline does mean, the Data status in Cellular in emulators Extended controls was set to Unregistred (off)

@donotsue thx for your hint! At the end I could figured out because I tested the urls in the browser!

We have some http get and posts in our ionic3 app which makes a HTTPS call to an external resource like https://smart.blabla.com If we create a simple bundle with ionic cordova build android anything is fine and anything is working as expected. If we create the release bundle with ionic cordova build android --release we have the problem that after every first open of the app on the first request to the cloud, the request is going wrong. No HTTP error or something like that. But the request is…