【问题标题】:Retrofit2 and kotlinRetrofit2 和 kotlin
【发布时间】:2016-03-07 16:03:24
【问题描述】:

我正在尝试将 Kotlin RxJava 和 retrofit2 结合起来。

@GET("/xxxxxxxxxxxx/{id}.json")
fun getHotel(@Part("id") id : String) : Observable<Response<Hotel>>

当我尝试调用这个方法时(getHotels()):

   var subscription = HotelsFactory.getHotelService((activity.applicationContext as App)
            .client)
        .getHotel(arguments.getInt("id").toString())
        .subscribeOn(Schedulers.computation())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({response -> showHotels(response)}) 
         {throwable ->       throwable.printStackTrace()}
    mSubscription.add(subscription)

我拿这个:

@Part 参数只能用于多部分编码。

【问题讨论】:

  • 你应该使用@Path而不是@Part

标签: android rx-java kotlin retrofit2


【解决方案1】:

问题是您正在尝试使用 @Part 注释,而您应该使用 @Path 注释,只需替换它,您就应该准备好了。

@Part,如错误所述,在提交多部分表单数据时应使用,而不是用于修改 URL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2021-10-05
    • 1970-01-01
    • 2018-11-27
    • 2018-04-16
    • 2020-04-18
    • 2019-11-08
    相关资源
    最近更新 更多