我一直试图使用almofire发布包含阿拉伯字符的参数。
当我发送拉丁字符时,一切都做得很好。
但是当我发送阿拉伯字符时,它看起来像这样? ???? ?? ?
我如何解决这个问题请帮助我。
我的代码:
var myUrls:String = "https//:wwww.mywebsite.com"
let parameters: Parameters = [
"user_id": "\(is_loged)",
"title": "\(title)",
"msg": "\(msg)",
"appKey": "\(staticsClass.AppKey)"
]
Alamofire.request(myUrls, method: .post, parameters: parameters ).responseJSON { response in
print("Request: \(String(describing: response.request))") // original url request
print("Response: \(String(describing: response.response))") // http url response
print("Result: \(response.result)") // response serialization result
if let json = response.result.value {
print("JSON: \(json)") // serialized json response
}
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)") // original server data as UTF8 string
let toast = Toast(text: NSLocalizedString("sent_successfully", comment: ""))
toast.show()
}
}
答案 0 :(得分:0)
您需要将Content-Type标头设置为请求:
var myUrls = URLRequest(url: URL(string: "https//:wwww.mywebsite.com")!)
myUrls("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
Alamofire.request(myUrls, method: .post, parameters: parameters ).responseJSON { response in
print("Request: \(String(describing: response.request))") // original url request
print("Response: \(String(describing: response.response))") // http url response
print("Result: \(response.result)") // response serialization result
if let json = response.result.value {
print("JSON: \(json)") // serialized json response
}
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)") // original server data as UTF8 string
let toast = Toast(text: NSLocalizedString("sent_successfully", comment: ""))
toast.show()
}
}