传递带有照片的用户ID POST Swift

时间:2015-08-05 10:34:40

标签: ios string post

我有一个上传功能,可以使用POST方法将照片发送到我的服务器。我现在还希望在此服务中包含变量userID(currentUser)。我有以下代码,但是当我将let param = ["userId" : "1"]切换为类似let param = [currentUser]的内容时,我收到了错误消息。 currentUser被声明为一个String,这是函数所要求的,所以我无法弄清楚什么是错的。

func myImageUpLoadRequest(){
        let myUrl = NSURL(string: "http://server.com/POSTTEST/imageUpload.php");

        let request = NSMutableURLRequest(URL:myUrl!);
        request.HTTPMethod = "POST";

        let param = ["userId" : "1"]

        let boundary = generateBoundaryString()

        request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

        let imageData = UIImageJPEGRepresentation(myImageView.image, 1)

        if(imageData==nil)  { return; }

        request.HTTPBody = createBodyWithParameters(param, filePathKey: "imagefile", imageDataKey: imageData, boundary: boundary)

0 个答案:

没有答案