Git Product home page Git Product logo

Comments (3)

liujingxing avatar liujingxing commented on June 10, 2024

添加文件用addFile方法

from rxhttp.

liujingxing avatar liujingxing commented on June 10, 2024

另外,RxHttp不支持单独获取okhttp3.Response,但支持获取OkResponse<T>对象,更加方便,仅需在toXxx方法后调用toXxxOkResponse方法即可,如下:

//await写法
RxHttp.get("../server/..")
    .toAwait<User>()  //可传入任意实体类
    .toAwaitOkResponse()  //返回 Await<OkResponse<User>>对象
    .awaitResult {
        val user = it.body()  //User对象
        val response = it.raw()  //okHttp3.Response对象
        val headers = it.headers()  //okhttp3.Headers对象
    }.onFailure {
        it.show()  //失败回调
    }


//Flow写法
RxHttp.get("../server/..")
    .toFlow<User>()
    .toFlowOkResponse()    //返回 Flow<OkResponse<User>>对象
    .catch {
        it.show()  //失败回调
    }.collect {
        val user = it.body()  //User对象
        val response = it.raw()  //okHttp3.Response对象
        val headers = it.headers()  //okhttp3.Headers对象
    }


//RxJava写法
RxHttp.get("../server/..")
    .toObservable<User>()
    .toObservableOkResponse()  //返回 Observable<OkResponse<User>>对象
    .subscribe({
        val user = it.body()  //User对象
        val response = it.raw()  //okHttp3.Response对象
        val headers = it.headers()  //okhttp3.Headers对象
    }, {
        it.show()  //失败回调
    })

from rxhttp.

xxxxxxH avatar xxxxxxH commented on June 10, 2024

非常感谢

from rxhttp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.