CapacitorHTTP iOS Error

Hello everyone. I’m having an issue while using the CapacitorHTTP in my project. Im trying to get items from a database via a url. For Android it works fine, I am able to retrieve the items but on iOS, I get this error in the log:

Here is what my get method looks like:

   async getLocations(): Promise<any> {
     const options = {
         url: 'https://example.com/my/api',
         headers: {
           'Content-Type': 'application/json',
         }
     };

  return await CapacitorHttp.get(options);

   }

Heres what Android looks like:

I followed this guide: Capacitor Http Plugin API | Capacitor Documentation

I have found this issue in the GitHub repo that is similar to my issue:

@jcesarmobile stated that it was fixed in 4.6.2 but im on 4.6.3 and im still seeing the issue.

Can anyone please help me get this working in iOS?

1 Like

Anyone have any ideas or can point me in the right direction?

Have you tried to use .request instead of get?

return await CapacitorHttp.request(options);

Yes, still shows the same error.

So I just decided to use cordova-plugin-advanced-http instead. In conclusion, CapacitorHttp does NOT work properly, not sure whats going on under the hood but switching to the cordova plugin worked in one shot. Thanks for you help @Hills90210!

1 Like

add .catch and print error messages, maybe there’s a more precise explanation

I have an issue with IOS as well with Capacitor/Http. It works in Android, and it also works in the web app. But for some reason in IOS I get an error with NSURL, some of which are logged that look exactly like your error.

I had this working fine with Cordova but “upgraded” to Capacitor with the hope of better performance and support for native apps. But I’m at the point where I may need to back out my changes and go back to what was working before.

Would love to know if anyone else was able to solve this issue, or has a working example that is proven on IOS. There has to be some

Not sure if this will help but there was some commonality between your output and mine:

https://forum.ionicframework.com/t/issue-with-capacitorhttp-on-ios/235142/4

Basically my issue was fixed using the line:

url = encodeURI(url);
1 Like