Alamofire获取响应-999 =使用URLRequestConvertible取消

时间:2016-01-28 09:18:34

标签: ios swift alamofire

我有关于Alamofire 3.0的问题,我正在尝试通过身份验证从服务器获取数据。当我运行它到我的设备iphone 6 ios 9.2.1没有响应,但在iphone 6 ios 9.2模拟器有响应。

我按照https://github.com/Alamofire/Alamofire#crud--authorization

中的alamofire文档中的说明进行操作

感谢您的回答。

类APIController {

 ...


enum Router: URLRequestConvertible {
    static let baseURLString = "link_with_user:password"
    static var OAuthToken: String?

    case myListing([String: AnyObject])

    var method: Alamofire.Method {
        switch self {

        case .myListing:return .GET
        }
    }

    var path: String {
        switch self {

        case .myListing:
            return "Listing.php"

        }
    }

    var URLRequest: NSMutableURLRequest {
        let URL = NSURL(string: Router.baseURLString)!
        let mutableURLRequest = NSMutableURLRequest(URL: URL.URLByAppendingPathComponent(path))
        mutableURLRequest.HTTPMethod = method.rawValue

        if let token = Router.OAuthToken {
            mutableURLRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-type")
            mutableURLRequest.setValue("Basic \(token)", forHTTPHeaderField: "Authorization")
        }

        switch self {
        case .myListing(let parameters):
            return Alamofire.ParameterEncoding.URL.encode(mutableURLRequest, parameters: parameters).0
        default:
            return mutableURLRequest
        }
    }
}


func getListing(){
   //This is how i call the enum
    Alamofire.request(Router.myListing(parameters!))
        .responseJSON { response in

            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
    }



}

}

0 个答案:

没有答案