Alamofire 小试牛刀

1、定义请求头

  let headers: HTTPHeaders = [

            "token": "W4SIjb3gHgJqgG8LRWj0jM==",

            "clienttype": "ios"

        ]

2、定义请求体

        let params : Parameters = ["inspectId" : ""]

3、请求URL       

        let urlStr = "http://123.57.27.38:8280/api/v1/inspectResultBaseInfo/index"

4、发起请求 当请求序列化为data时,encoding = URLEncoding.default, 当请求序列化为json时,encoding = JSONEncoding.default

        Alamofire.request(urlStr, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { (response) in

            print(response)

            

            if let json = response.result.value {

                print("JSON:(json)")

            }

        }

参考资料:http://www.jianshu.com/p/f8c3adb056cf

原文地址:https://www.cnblogs.com/yang-shuai/p/7463709.html