RxSwift-网络

2019-08-13  本文已影响0人  Code_人生
    func testResponseDemo(){
        URLSession.shared.rx.response(request: URLRequest(url: self.url))
            .subscribe(onNext: { (response,data) in
                print("response:\(response) \n data:\(data)" )
            }, onError: { (error) in
                print("error:\(error)")
            }, onCompleted: {
                print("网络请求完成")
            }) {
                print("销毁咯")
            }.disposed(by: self.disposeBag)
    }
    func testDataDemo(){
        URLSession.shared.rx.data(request: URLRequest(url: self.url))
            .subscribe(onNext: { (data) in
                print("data:\(data)" )
            }, onError: { (error) in
                print("error:\(error)")
            }, onCompleted: {
                print("网络请求完成")
            }) {
                print("销毁咯")
            }.disposed(by: self.disposeBag)
    }
    func testJsonDemo(){
        URLSession.shared.rx.json(request: URLRequest(url: self.url))
            .subscribe(onNext: { (json) in
                print(json)
            }, onError: { (error) in
                print("error:\(error)")
            }, onCompleted: {
                print("网络请求完成")
            }) {
                print("销毁咯")
            }.disposed(by: self.disposeBag)
    }
上一篇 下一篇

猜你喜欢

热点阅读