Reputation: 992
I am attempting to use @ionic-native/http
on iOS and Web with no success. App starts on both platforms, but the plugin does not work.
I hope that covers the most important ones.
ionic start myApp tabs
npm install --save @capacitor/cli @capacitor/core
npm run build --prod
npx cap init <name> <id>
npx cap add ios
npx cap copy
npx cap open ios
npm install cordova-plugin-advanced-http
npm install @ionic-native/http
npx cap sync
According to the documentation (which I might have misunderstood) that should be it.
When attempting to call an API:
Native: tried calling HTTP.get, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator
I know I don't use Cordova per se but shouldn't it be covered by npx cap sync
?
[error] - ERROR {"line":38,"column":38,"sourceURL":"capacitor://localhost/tab2-tab2-module.js"}
Upvotes: 3
Views: 3642
Reputation: 992
I was lucky to finally find some more information.
I am not really sure why, but this additional plugin helped https://github.com/sneas/ionic-native-http-connection-backend. Requests can be made through HttpClient
and they use Cordova plugin so that they bypass proxy.
Capacitor won't work on the browser according to https://github.com/ionic-team/capacitor/issues/767#issuecomment-415481452
So my assumption that it will was wrong. Previously mentioned plugin will delegate requests through HttpClient
so it is nice workaround for the browser, although won't fix CORS issue.
CORS issue at this point can be handled by a proxy.
Upvotes: 2