简体   繁体   中英

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

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
}

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

在此处输入图像描述

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"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM