Swift 3.0, Alamofire 4.0 Extra Argument 'Method' in Call

Extra argument in call Alamofire Swift

you have create simple method.you need to create completion block parameter

try this code

  class func checkServerForLogin(_ url:String,email: String, password: String,success:@escaping (JSON) -> Void, failure:@escaping (Error) -> Void) {

let parameters = [
"email": email,
"password": password
] as [String : Any]

Alamofire.request(url, method: .post, parameters: parameters).responseString { (response) in

if response.result.isSuccess {
let resJson = JSON(response.result.value!)
success(resJson)
}
if response.result.isFailure {
let error : Error = response.result.error!
failure(error)
}
}
}

AuthService.checkServerForLogin(URL_CHECK_LOGIN, email: email_input, password: password_input, success: { (responseObject) in
print(responseObject)
}) { (error) in
print(error.localizedDescription)
}

Extra argument 'method' in call

I got the issue, I have to use JSONEncoding.default instead of .JSON, so the new syntax is

Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: JSONEncoding.default, headers: [:])

Alamofire 4.0 extra argument 'method' in call when wrapped in static function

Issue resolved for the time being. It was a scoping issue with the baseURL variable not being inside the method. The following will build for me.

func registerUser(firstName: String, lastName: String, email: String, username: String, password: String, profilePicture: String, completion: @escaping(JSON?) -> ()) {
let baseURL = "url"
let params: [String:Any]? = [
"first_name" : firstName,
"last_name" : lastName,
"email" : email,
"username" : username,
"password" : password,
"profile_pic" : profilePicture
]

Alamofire.request("\(baseURL)/users/create", method: .post, parameters: params, encoding: JSONEncoding.default, headers: nil).responseJSON { response in
switch response .result {
case .success(let value) :
completion(JSON(value))
case .failure(let error) :
let error = error as Error
print(error.localizedDescription)
completion(nil)
}
}
}

Alamofire Swift 3.0 Extra argument in call

According to Alamofire documentation for version 4.0.0 URL request with HTTP method would be followings:

Alamofire.request("https://httpbin.org/get") // method defaults to `.get`    
Alamofire.request("https://httpbin.org/post", method: .post)
Alamofire.request("https://httpbin.org/put", method: .put)
Alamofire.request("https://httpbin.org/delete", method: .delete)

So your url request will be:

Alamofire.request(patientIdUrl, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil)

and a sample request will be:

Alamofire.request(url, method: .post, parameters: param, encoding: JSONEncoding.default, headers: [AUTH_TOKEN_KEY : AUTH_TOKEN])
.responseJSON { response in
print(response.request as Any) // original URL request
print(response.response as Any) // URL response
print(response.result.value as Any) // result of response serialization
}

Hope this helps!

Alamofire extra argument 'method' in call

Check that the structure of your parameters and headers are right, if not the error you mentioned appears. It should look like that:

Alamofire.request("\(Config().apiAdminTableGroup)\(group.id)/", method: .put, parameters: ["param1":"1", "param2":"2"], encoding: JSONEncoding.default, headers: ["Authorization": "Basic xxx"])

Alamofire Extra argument 'method' call

First your params are wrong you need to pass a dictionary [key:value] and then you need to convert it to json and put in your request body, also if you are using Alamofire.request you don't need pass urlString, only a request, try with this code

func postMethodUploadDataToServerLoginPage() {

let paramToSend = ["name":"Thobio Joseph","googleid":"24356567890uyy4546","email":"jthobio2@gmail.com","avatar":"https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAv0AAAAJDZjZGJjMTFjLWNiNzAtNGYzNy1iMDE4LTA2MzBmNzUwZGExNQ.jpg"]

let request = NSMutableURLRequest(url: URL(string: loginUrl)!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try! JSONSerialization.data(withJSONObject: parameters)

Alamofire.request(request).responseJSON { (response) in

switch response.result {

case .success:
print(response)

case .failure(let error):
failure(0,"Error")

}

}

Hope this helps

Alamofire.request Extra argument 'method' in call

Use a URLRequest:

var request = URLRequest(url: url!)
request.httpMethod = "GET"

Alamofire.request(request)
.validate()
.responseJSON { (response) in
//
}


Related Topics



Leave a reply



Submit