Retrofit2 和科特林

Retrofit2 and kotlin

我正在尝试结合使用 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 parameters can only be used with multipart encoding.

问题是您尝试在本应使用 @Path 注释的地方使用 @Part 注释,只需替换它即可。

@Part,正如错误描述的那样,应该在提交多部分表单数据时使用而不是为了修改 URL。