我正在遵循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没有成员POST" 这是Http.swift文件。 。 https://github.com/aerogear/aerogear-ios-http/blob/master/AeroGearHttp/Http.swift
答案 0 :(得分: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
})