我在Alamofire中使用Moya。它们紧密结合在一起。然而,Moya或Alamofire在POST请求中转义了我的body json参数。
我正在寻找在哪里以及如何防止这种逃逸发生。
示例:
{
"credentials": {
"secret":
jJWoBkc64O0VzcjRQv4MIuQv0HgRLiNQZL7GAhtINz6EKuaK+u+YkBMi9z3v6rqLBh8TD8lIO3F+5t7iJB/FJw==查看转义为\/FJw==的/FJw==
发布于 2018-07-13 20:53:12
不幸的是,这个技巧目前对我是有效的:
struct JSONStringArrayEncoding: ParameterEncoding {
func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
var urlRequest = urlRequest.urlRequest
let data = try! JSONSerialization.data(withJSONObject: parameters!, options: JSONSerialization.WritingOptions.prettyPrinted)
let json = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
if let json = json {
print(json)
let newJson = json.replacingOccurrences(of: "\\/", with: "/")
urlRequest?.httpBody = newJson.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue));
}
return urlRequest!
}
}然后在任务中
var task: Task {
switch self {
case
.postConnectAddress:
return .requestParameters(parameters: parameters! , encoding: JSONStringArrayEncoding())https://stackoverflow.com/questions/51309104
复制相似问题