我正在学习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没有成员帖子“这里是Http.swift文件。。https://github.com/aerogear/aerogear-ios-http/blob/master/AeroGearHttp/Http.swift
发布于 2017-08-29 18:06:17
http中没有POST函数,必须这样使用request:
let http = Http(baseURL: "http://yourserver.com")
http.request(method: .post, path: "/postendpoint", parameters: ["key": "value"],
completionHandler: {(response, error) in
// handle response
})https://stackoverflow.com/questions/45808682
复制相似问题