问题描述
I have read all the questions on this issue this and this. I have the following code
let fullURL = God.getFullURL(apiURL: self.apiUrl)
if (getOrPost == God.POST) {
Alamofire.request(fullURL, method: .POST, AnyObject: self.postData?, encoding:.JSONEncoding.default, headers: nil).responseJSON{ response in
self.responseData = response.result.value
}
} else if (getOrPost == God.GET) {
Alamofire.request(fullURL, method : .GET, Parameters: getData, encoding:.JSONEncoding.default, headers: nil).responseJSON{ response in
self.responseData = response.result.value
}
}
我的 Swift 和 Xcode 版本是
My Swift and Xcode versions are
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9
Version 8.2.1 (8C1002)
我的 pod 文件是
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'Buseeta' do
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'
end
pod 'AlamofireObjectMapper', '~> 4.0'
pod 'SwiftyJSON'
我在两个 Alamofire 请求行上都收到 Extra argument 'method' in call
错误.
I get Extra argument 'method' in call
error on both Alamofire request lines.
不要在没有仔细检查的情况下将这个问题标记为重复.我已经完全按照重复的问题修复了代码.
Dont go mark this question as duplicate without carefully checking. I have fixed the code exactly as per the duplicate questions.
编辑 1
我在删除标题后尝试,在 .POST
和 .GET
I tried after removing the headers, same issue on .POST
and .GET
let fullURL = God.getFullURL(apiURL: self.apiUrl)
if (getOrPost == God.POST) {
Alamofire.request(fullURL, method: .POST, AnyObject: self.postData?, encoding:.JSONEncoding.default).responseJSON{ response in
self.responseData = response.result.value
}
} else if (getOrPost == God.GET) {
Alamofire.request(fullURL, method : .GET, Parameters: getData?, encoding:.JSONEncoding.default).responseJSON{ response in
self.responseData = response.result.value
}
}
编辑 2
if (getOrPost == God.POST) {
Alamofire.request(fullURL, method: .post, parameters: self.postData?, encoding:.JSONEncoding.default).responseJSON{ response in
self.responseData = response.result.value
}
} else if (getOrPost == God.GET) {
Alamofire.request(fullURL, method : .get, parameters: getData?, encoding:.JSONEncoding.default).responseJSON{ response in
self.responseData = response.result.value
}
}
编辑 3
我换成了 method : HTTPMethod.get,
仍然没有变化.同样的问题.
I replaced with method : HTTPMethod.get,
still no change. Same issue.
推荐答案
你需要使用另一个函数来上传数据:
You need to use another function to upload data:
func upload(
_ data: Data,
to url: URLConvertible,
method: HTTPMethod = .post,
headers: HTTPHeaders? = nil)
-> UploadRequest
GET 请求的参数必须是 [String: Any] 类型
And parameters for GET request must be of type [String: Any]
这篇关于Swift 3.0、Alamofire 4.0 调用中的额外参数“方法"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!