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)
}
网友评论