我尝试结合使用 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.
最佳答案
问题是您正在尝试使用 @Part
批注,而您应该使用 @Path
批注,只需替换它,您就应该一切就绪。
@Part
,如错误所述,应该在提交多部分表单数据时使用,而不是为了修改 URL。
关于android - Retrofit2 和 Kotlin ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35848383/