您好,我正在尝试覆盖来自一个特定api调用的baseUrl,当使用@Url作为api方法的参数时,它似乎不起作用。
下面是我的Api类方法
@POST
fun getUserDetails(@Body body: request, @Url authUrl : String): Single<Response<ResponseData>>
对cals进行编码并发出请求
private fun getApi(): Api {
val gson = GsonBuilder().setLenient().create()
val httpClient = myNetworkHelper.createHttpClient()
val retrofit = Retrofit.Builder()
.baseUrl("http://defaultBaseUrl")
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
return retrofit.create(Api::class.java)
}
override fun getUserDetails(someRequestData, "http://dynamic/getuserDetails): Single<Response<ResponseData>> {
return getApi().getUserDetails(body, url)
}
上面的结果是向这个url发出一个请求。
http://defaultBaseUrl/http://dynamic/getuserDetails
而不是:
http://dynamic/getuserDetails
发布于 2018-07-17 23:25:29
这是来自Retrofit @GET
annotation的文档:
@Documented
@Target(METHOD)
@Retention(RUNTIME)
public @interface GET {
/**
* A relative or absolute path, or full URL of the endpoint. This value is optional if the first
* parameter of the method is annotated with {@link Url @Url}.
* <p>
* See {@linkplain retrofit2.Retrofit.Builder#baseUrl(HttpUrl) base URL} for details of how
* this is resolved against a base URL to create the full endpoint URL.
*/
String value() default "";
}
所以应该把@Url
作为第一个参数,所以我认为这是可行的:
@POST
fun getUserDetails(@Url authUrl: String, @Body body: request): Single<Response<ResponseData>>
https://stackoverflow.com/questions/51384810
复制相似问题