1

I'm following a tutorial for OAuth 2 authentication, and it's a little bit old so changes may have been made to the files it uses. But I am trying to make an Http POST request using the AeroGear module. Here's how my function looks like:

@IBAction func share(_ sender: AnyObject) {
    // TODO: your turn to code it!
    let googleConfig = GoogleConfig(
        clientId: "removed",                               // [1] Define a Google configuration
        scopes:["https://www.googleapis.com/auth/drive"])                // [2] Specify scope

    let gdModule = AccountManager.addGoogleAccount(config: googleConfig)     // [3] Add it to AccountManager
    self.http.authzModule = gdModule                                 // [4] Inject the AuthzModule
    // into the HTTP layer object

    let multipartData = MultiPartData(data: self.snapshot(),         // [5] Define multi-part
        name: "image",
        filename: "incognito_photo",
        mimeType: "image/jpg")
    let multipartArray =  ["file": multipartData]


    self.http.POST("https://www.googleapis.com/upload/drive/v2/files",   // [6] Upload image
        parameters: multipartArray,
        completionHandler: {(response, error) in
            if (error != nil) {
                self.presentAlert("Error", message: error!.localizedDescription)
            } else {
                self.presentAlert("Success", message: "Successfully uploaded!")
            }
    })

}

http was initialized earlier on to be of type Http.

However, I get the error: "Http has no member POST" Here is the Http.swift file. . https://github.com/aerogear/aerogear-ios-http/blob/master/AeroGearHttp/Http.swift

1 Answers1

0

There is no POST function in http, you have to use request like this:

let http = Http(baseURL: "http://yourserver.com")
http.request(method: .post, path: "/postendpoint",  parameters: ["key": "value"],
                    completionHandler: {(response, error) in
     // handle response
})
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176