所需的请求部分“有效负载”不存在Swift

时间:2019-04-24 08:01:04

标签: ios swift alamofire

我正在尝试通过Alamofire发出发布请求,并且不存在“要求的请求”部分“有效载荷”,这是我第一次看到或处理此类请求,正如您在代码中看到的,我有mediaType可以是文本,图像,...等

注意:有效负载为PayloadDto JSON

func send(){

  let body: [String:String] = [
                "text":message,
                "mediaType":"TEXT", //or image , video ,voice 
                "id":id
            ]

   let payload = [
                payload:"\(body)"
            ]

      Alamofire.upload(multipartFormData: { MultipartFormData in
                for (key, value) in payload {
                    MultipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
                }
            }, usingThreshold: UInt64.init(),
               to: "url",
               method: .post,
               headers:["Authorization": "access token"],
                encodingCompletion: { encodingResult in
                    switch encodingResult {
                    case .success(let upload, _, _):
                        upload.responseJSON { response in
                          print("response"\(response))
                                }
                                return
                            }
                        }
                    case .failure(let error):
                        print(error)
                    }
          })
}

0 个答案:

没有答案