参数以表单的形式上传 但是并不是图片视频文件流的形式上传(特殊请求模式)

    Alamofire.request(loginSTR, method: .post, parameters: para, encoding: URLEncoding.init(destination: .methodDependent), headers: ["Content-Type":"application/x-www-form-urlencoded","Accept":"application/json;charset=utf-8"]).responseJSON { (data) in}

class TBUploadDataManager: NSObject {

public static let share = TBUploadDataManager()

public func loginData(parameters:[String:String]?,
                      hostUrl:String,type:tbUploadType, comparBlock:@escaping (SessionManager.MultipartFormDataEncodingResult) -> Void){
    Alamofire.upload(
        multipartFormData: { multipartFormData in
            if parameters != nil{
                for parameter in parameters!{
                    
                    multipartFormData.append((parameter.value.data(using: .utf8)!), withName: parameter.key, mimeType: type.rawValue)
                }
            }
            
    },
        to: hostUrl,
        encodingCompletion: { encodingResult in
            //把encodingResult返回出去
            comparBlock(encodingResult)
    }
    )
}

}
//实现
TBUploadDataManager.share.loginData(parameters: para as! [String : String], hostUrl: loginSTR, type: tbUploadType.formdata) { (encodingResult) in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in

你可能感兴趣的:(参数以表单的形式上传 但是并不是图片视频文件流的形式上传(特殊请求模式))