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 ?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With