2016-03-08 134 views
0

我需要向我的应用程序的API发送登录请求,我没有对API进行编码,有人正在为我们做这件事,所以我使用邮递员来测试请求并使用邮递员我这样做:用Alamofire发送HTTP Body中的数据

URL : {{dev}}/customer/login-mock 

Body/x-www-form-urlencoded : 

key = toto/value = toto 
key = toto/value = toto 

有了这个,我得到了答复。

但我不知道如何用Alamofire实现它。我有点失落,而且我看到的所有教程都使用url params将参数发送到它们的api。

我,我可以用一个FUNC像:

RequestManager.request(.POST, "customer/login-mock", body: [username: "toto", password: "toto"]) 

class RequestManager: NSObject { 
    request(method, url, body) { 
     Alamofire.request(someRequest).responseJSON{response in ....} 
    } 

} 

感谢您的帮助!

回答

0

使用此: -

Alamofire.request(.GET, query, parameters : param, headers : headers).responseJSON { (response) -> Void in 
       switch response.result 
       { 
       case .Success: //Success 
        if let value = response.result.value 
        { 
         completion(result: value, error: "") 
         print(value) 
        } 
       case .Failure(let error): //error 
        completion(result: "", error: error) 
       } 
      }