Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

whitespace in url - alamofire

I'm trying to post a http request using alamofire. my request is as follows:

let url = "\(myBaseURL)/{name:adriana lima}"
Alamofire.request(url.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!, method: .post)

I tried some encoding types such as :

urlFragmentAllowed , whitespaces

but they're not working.

I know if i use parameters, whitespace would be handled but in this case, i have to pass parameters inside of url. but it results error. how can i post this and how should i encode it ?

like image 343
Hos Ap Avatar asked May 18 '17 10:05

Hos Ap


Video Answer


1 Answers

You need to encode the URL before passing it to alamofire method. using addingPercentEncoding.

let urlString = "\(myBaseURL)/{name:adriana lima}"
guard let encodedURL = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) else {
    //Invalid URL
    return 
}
like image 51
Saif Avatar answered Oct 10 '22 00:10

Saif