diff --git a/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift b/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift index 963b16225f..40cef58dc6 100644 --- a/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift +++ b/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift @@ -141,7 +141,7 @@ class HttpRequestHandler { } public static func request(_ call: CAPPluginCall, _ httpMethod: String?, _ config: InstanceConfiguration?) throws { - guard let urlString = call.getString("url")?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { throw URLError(.badURL) } + guard var urlString = call.getString("url") else { throw URLError(.badURL) } let method = httpMethod ?? call.getString("method", "GET") // swiftlint:disable force_cast @@ -151,6 +151,11 @@ class HttpRequestHandler { let connectTimeout = call.getDouble("connectTimeout") let readTimeout = call.getDouble("readTimeout") + if urlString == urlString.removingPercentEncoding { + guard let encodedUrlString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { throw URLError(.badURL) } + urlString = encodedUrlString + } + let request = try CapacitorHttpRequestBuilder() .setUrl(urlString) .setMethod(method)