gpt4 book ai didi

ios - 在 alamofire swift ios 中发布阿拉伯字符

转载 作者:行者123 更新时间:2023-11-30 11:36:18 25 4
gpt4 key购买 nike

我一直在尝试使用 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()


}
}

最佳答案

您需要设置 Content-Type header 来请求:

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()


}
}

关于ios - 在 alamofire swift ios 中发布阿拉伯字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49729884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com