Search code examples
iosswiftalamofire

Alamofire GET request with åäö (special characters), invalid url


I'm trying to send an API get request with alamofire, but when i use the following url: https://stuntmans.evosale.se/admin/api/dräkt , the special character in "dräkt" is returning an invalid url as response. How would i go about using special characters with alamofire?

Thanks in advance!

Here is a part of the code:

let headers: HTTPHeaders = [
            .authorization(username: "Username", password: "Password"),
            .accept("application/json")]

        AF.request(https://stuntmans.evosale.se/admin/api/dräkt, headers: headers).validate().responseJSON { response in

Solution

  • Solved this by replacing the characters "åäö" with the corresponding characters they're supposed to represent in url, below is the code:

    var result = Url
            zip(["å", "ä", "ö"],["%C3%A5", "%C3%A4", "%C3%B6"]).forEach {
                result = result.replacingOccurrences(of: $0, with: $1, options: .literal)
            }
    
    print (result) // the result