Home > Enterprise >  How to send Apostrophe ('s) in API request(Alamofire) swift 5?
How to send Apostrophe ('s) in API request(Alamofire) swift 5?

Time:09-08

I'm trying to send Apostrophe('s) in request using Alamofire. I've tried below things but didn't get success

1) addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
2) addingPercentEncoding(withAllowedCharacters: .alphanumerics)

3) func utf8EncodedString()-> String {
    let messageData = self.data(using: .nonLossyASCII)
    let text = String(data: messageData!, encoding: .utf8) ?? ""
    return text
}

CodePudding user response:

After, searching relentlessly then finally I found one solution that we can turn off smart punctuation on particular textfield(smartQuotesType method).

enter image description here

CodePudding user response:

try this:

let stringText = "This is my string"
let datas = ["myString": stringText]
guard let upload = try? JsonEncoder().encode(datas) else { return }

at this point send "upload" on your server, decode Json and use "myString" as variable for example in php:

$json = file_get_contents('php://input');
$array = json_decode($json, true);    
$myString = $array["myString"];
  • Related