Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios POST方法在swift 3.0 Alamofire 4.0中不起作用?_Ios_Swift3 - Fatal编程技术网

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”的响应……此代码中是否有错误。

很多事情都可能出错。如果要调试,我会检查以下几件事:

  • 如果我想使用PNG,我可能会在这段代码中使用
    UIImagePNGRepresentation(…)
    ,而不是
    UIImageJPEGRepresentation
  • 如果我想使用JPEG,我会将
    multipartFormData.append(imageData,名称:“file”,文件名:“file.png”,mimeType:“image/png”)
    更改为
    multipartFormData.append(imageData,名称:“file”,文件名:“file.jpg”,mimeType:“image/JPEG”)
  • 如果是(2),请尝试将
    uiimagejpegresentation(图像,1)
    更改为
    uiimagejpegresentation(图像,0.5)
    。它可能会失败,因为图像太大,因此应用更高的压缩可能会发现问题

  • 很多事情都会出错。如果要调试,我会检查以下几件事:

  • 如果我想使用PNG,我可能会在这段代码中使用
    UIImagePNGRepresentation(…)
    ,而不是
    UIImageJPEGRepresentation
  • 如果我想使用JPEG,我会将
    multipartFormData.append(imageData,名称:“file”,文件名:“file.png”,mimeType:“image/png”)
    更改为
    multipartFormData.append(imageData,名称:“file”,文件名:“file.jpg”,mimeType:“image/JPEG”)
  • 如果是(2),请尝试将
    uiimagejpegresentation(图像,1)
    更改为
    uiimagejpegresentation(图像,0.5)
    。它可能会失败,因为图像太大,因此应用更高的压缩可能会发现问题

  • 不确定它是否解决了问题,但在Swift 3注释中
    [String:Any]
    ——或者忽略注释,因为字典显然是
    [String:String]
    ——并删除对
    任何对象的强制转换,你的意思是打印“失败”吗?不确定它是否解决了问题,但在Swift 3注释中
    [String:Any]
    –或者省略注释,因为字典显然是
    [String:String]
    –并删除对
    任何对象的强制转换
    您的意思是打印“失败”吗?即使我不发送图像,我只发送参数,它也不工作即使我不发送图像,我只发送参数,它也不工作