我将JSON对象发送到我的API并以JSON格式接收响应。 以下是PostMan中工作API的快照
但是当我在Alamofire发送请求时,我收到 responseSerializationFailed 错误。以下是代码。
self.url = URL(string: "http://xyzxyz/api/CheckQRCode")!
let imageData:NSData = UIImagePNGRepresentation(image)! as NSData
let strBase64:String = imageData.base64EncodedString(options: .lineLength64Characters)
let parameters: [String:Any] = [
"QrCode": carIdentifier,
"qrCodeImageDumy": strBase64
]
let headers: HTTPHeaders = [
"Content-Type":"application/json",
"Accept":"application/json"
]
Alamofire.request(self.url!, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
.responseJSON { (response) -> Void in
switch response.result {
case .success:
guard let rawJson = response.result.value as? [String: Any] else {
print("Received Malformed data from server")
return
}
let formattedJson = JSON(rawJson)
case .failure(let error):
errorBlock(error)
}
}