import UIKit
import Alamofire
import SwiftyJSON
enum MethodType {
case get
case post
}
class NetworkTools: NSObject {
class func requestdData(_ type : MethodType,URLString:String,parameters:[String : Any]? = nil,finishedCallback: @escaping (_ result : Any)->()){
let method = type == .get ? HTTPMethod.get : HTTPMethod.post
//请求头
let requestHeader:HTTPHeaders = [
"Accept":"application/json"]
Alamofire.request(URLString, method: method, parameters: parameters, encoding: URLEncoding.default, headers: requestHeader).responseJSON { (response) in
guard let request = response.result.value else {
print(response.result.error!)
return
}
finishedCallback((request))
}
}
}
网友评论