alamofire快速上传URL中带有json的多格式数据

时间:2019-09-25 23:03:33

标签: ios swift alamofire

有没有一种方法可以使用多格式数据在Alamofire上传中向url添加json enpoint需要使用这种格式的

网址
  

http://server.com/api/upload?jsonRes= {jsonobejecthere}

我已经尝试过了

 let jsonRes = "{\"destination\":\"\(params!["destination"]!)\",\"origin\":\"\(params!["origin"]!)\",\"score\":\"\(params!["score"]!)\",\"token\":\"\(params!["token"]!)\",\"vehicleId\":\"\(params!["vehicleId"]!)\"}"
    guard let jsonencode = jsonRes.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {return}
    let urlRequest = startOffUrl + middleUrl + "/upload?jsonRe=" + jsonencode

响应为: http://server.com/api/upload?jsonRe=%7B%22destination%22%3A%22M%C3%ADo%22,%22origin%22%3A%22Casa%22,%22score%22%3A%2290%22,%22token%22%3A%22cb31d58d20c9561b7b87fa2e90c8bf24%22,%22vehicleId%22%3A%22EN9420A%22%7D 不使图像为空 图片为空 上传响应为FAILURE:responseValidationFailed(原因:Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(代码:500))

成为json的对象是

let parameters: [String: String] = [
        "destination": self.destinyInput.textField.text!,
        "origin": self.originInput.textField.text!,
        "score":  dataValueResponse.description,//"100",
        "token":tokenApp,
        "vehicleId":self.searchTextField.text!
    ]

0 个答案:

没有答案