Retrofit2和kotlin

Ill*_*lyk 3 android kotlin rx-java retrofit2

我试着将Kotlin RxJava和retrofit2结合起来.

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

当我尝试调用此方法时(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)
Run Code Online (Sandbox Code Playgroud)

我拿这个:

@Part参数只能与多部分编码一起使用.

Bob*_*ke4 5

问题是你正在尝试使用@Part注释,你应该使用@Path注释,只需替换它,你应该全部设置.

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