1

我正在关注 OAuth 2 身份验证的教程,它有点旧,因此可能已对其使用的文件进行了更改。但我正在尝试使用 AeroGear 模块发出 Http POST 请求。这是我的函数的样子:

@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 早先被初始化为 Http 类型。

但是,我收到错误消息:“Http has no member POST” 这是 Http.swift 文件。. https://github.com/aerogear/aerogear-ios-http/blob/master/AeroGearHttp/Http.swift

4

1 回答 1

0

http中没有POST功能,你必须使用这样的请求:

let http = Http(baseURL: "http://yourserver.com")
http.request(method: .post, path: "/postendpoint",  parameters: ["key": "value"],
                    completionHandler: {(response, error) in
     // handle response
})
于 2017-08-29T10:06:17.090 回答