【发布时间】:2020-07-13 15:46:52
【问题描述】:
我已经完成了 alamofire 多部分表单数据上传的所有工作,但添加了不记名令牌。我们使用 Oauth 2.0,我们的文件需要令牌在我们的系统中进行身份验证。我只找到了一种方法来传递在我们当前系统中不起作用的用户名和密码。有没有办法将不记名令牌传递给php?
AF.upload(multipartFormData: { multipartFormData in
for (key, value) in parameters {
multipartFormData.append(value.data(using: .utf8)!, withName: key)
}
if let jpegData = image.jpegData(compressionQuality: 1.0) {
multipartFormData.append(jpegData, withName: "file", fileName: "image", mimeType: "image/jpeg")
}
}, to: "https:website" )
.uploadProgress{ progress in
//print("Upload Progress: \(self.progress.fractionCompleted)")
}
.response { response in
if response.response?.statusCode == 200 {
print("OK. Done")
print((NSString(data: response.data!, encoding:
String.Encoding.utf8.rawValue)! as String))
}else if response.response?.statusCode == 406{
print("error")
DispatchQueue.main.sync{
let alert = UIAlertController(title: "Error", message:
"Person has not been set up.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "close", style: .default, handler: { action in
DispatchQueue.main.async{
self.progressUiView.isHidden = true
self.dismiss(animated: true, completion: nil)
}
}))
self.present(alert, animated: true)
}
}else{
print(response.response?.statusCode)
}
}
【问题讨论】:
-
在此处添加您尝试过的代码。
-
添加了代码。抱歉有点乱。
-
看看我在想的代码,也许
for (key, value) in parameters { multipartFormData.append(value.data(using: .utf8)!, withName: key) }你可以在那里添加不记名令牌 -
这不是您添加不记名令牌的地方。看看我的回答。
标签: ios swift alamofire swift5