Ios POST方法在swift 3.0 Alamofire 4.0中不起作用?
以下是我的参数Ios POST方法在swift 3.0 Alamofire 4.0中不起作用?,ios,swift3,Ios,Swift3,以下是我的参数 var comment: [String:AnyObject] = [:] comment = [ "txtUsername": (txtUsername?.text)! as AnyObject, "txtPassword": (txtPassword?.text)! as AnyObject ] post方法函数包含以下代码 Alamofire.upload( multipartFormD
var comment: [String:AnyObject] = [:]
comment = [
"txtUsername": (txtUsername?.text)! as AnyObject,
"txtPassword": (txtPassword?.text)! as AnyObject
]
post方法函数包含以下代码
Alamofire.upload(
multipartFormData: { multipartFormData in
for (key, value) in Param {
multipartFormData.append((value.data(using: .utf8))!, withName: key)
}
let image = UIImage(named: "bodrum.png")!
if let imageData = UIImageJPEGRepresentation(image, 1)
{
multipartFormData.append(imageData, withName: "file", fileName: "file.png", mimeType: "image/png")
}
},
to: webpath,
encodingCompletion:
{
encodingResult in
switch encodingResult
{
case .success(let upload, _, _):
upload.responseJSON
{
response in
guard case .success(let rawJSON) = response.result else {
return
}
guard let json = rawJSON as? [String: String] else {
return
}
if json["Success"] == "True"{
print("Success")
}
else{
print("Failure")
}
}
case .failure(let encodingError):
print(encodingError)
}
}
)
在objective c中,我的Web服务工作成功,但在使用此代码时,它总是给出“false”的响应……此代码中是否有错误。很多事情都可能出错。如果要调试,我会检查以下几件事:
UIImagePNGRepresentation(…)
,而不是UIImageJPEGRepresentation
multipartFormData.append(imageData,名称:“file”,文件名:“file.png”,mimeType:“image/png”)
更改为multipartFormData.append(imageData,名称:“file”,文件名:“file.jpg”,mimeType:“image/JPEG”)
uiimagejpegresentation(图像,1)
更改为uiimagejpegresentation(图像,0.5)
。它可能会失败,因为图像太大,因此应用更高的压缩可能会发现问题很多事情都会出错。如果要调试,我会检查以下几件事:
UIImagePNGRepresentation(…)
,而不是UIImageJPEGRepresentation
multipartFormData.append(imageData,名称:“file”,文件名:“file.png”,mimeType:“image/png”)
更改为multipartFormData.append(imageData,名称:“file”,文件名:“file.jpg”,mimeType:“image/JPEG”)
uiimagejpegresentation(图像,1)
更改为uiimagejpegresentation(图像,0.5)
。它可能会失败,因为图像太大,因此应用更高的压缩可能会发现问题不确定它是否解决了问题,但在Swift 3注释中
[String:Any]
——或者忽略注释,因为字典显然是[String:String]
——并删除对任何对象的强制转换,你的意思是打印“失败”吗?不确定它是否解决了问题,但在Swift 3注释中[String:Any]
–或者省略注释,因为字典显然是[String:String]
–并删除对任何对象的强制转换
您的意思是打印“失败”吗?即使我不发送图像,我只发送参数,它也不工作即使我不发送图像,我只发送参数,它也不工作