Home > Software design >  Https address behaves differently on ios and android
Https address behaves differently on ios and android

Time:06-14

Currently modding logging logic for client with working Android app to also work on iOS. App is using DIO to make and handle https calls. Addresses are stored in a separate file as strings (lets call it 'settings').

Obviously cannot provide original links but it goes something like this:

const String firstUrl = 'https://best-service-ever.com/access/';
const String secondUrl = 'https://another-good-service.com';

Currently code looks like this in logging script:

static Uri get firstUri => Uri.parse(settings.firstUrl);

  static Uri get loginUri =>
      firstUri.resolve('login').replace(queryParameters: <String, dynamic>{'service': settings.secondUrl});

Android generates good loginUri- https://best-service-ever.com/access/login?service=https://another-good-service.com

But for some miraculous reason on ios loginURI is https://best-service-ever.com/login?service=https://another-good-service.com.

Why and how the endpoint would be lost while parsing and only on one platform?

**Also I can't just modify resolve('access/login') i need the address in multiple places as is.

**Also I'm currently running Flutter channel stable 2.10.5 on macOS 11.6.5

CodePudding user response:

please try this way

const String firstUrl = 'https://best-service-ever.com/access/login';
const String secondUrl = 'https://another-good-service.com';
Uri  loginUri = Uri.parse(
    firstUrl).replace(queryParameters: <String, dynamic>{'service':secondUrl}); 
    print(loginUri); 

CodePudding user response:

It looks like it might be a bug in flutter. I would then maybe work around it by doing it like this

String base = 'https://best-service-ever.com/';
String get firstUrl => '${base}access/';
String secondUrl = 'https://another-good-service.com';

static Uri get firstUri => Uri.parse(settings.firstUrl);
static Uri get base => Uri.parse(settings.base);
static Uri get loginUri =>
    base.resolve('access/login').replace(queryParameters: <String, dynamic>{'service': settings.secondUrl});

that way you can still use the original firstUrl in the rest of the code

CodePudding user response:

Instead of using Uri.parse try Uri.https maybe it helps. Check out this official link for more information

  • Related