gpt4 book ai didi

android - RxJava 2 Retrofit 和动态 url 以及 @url 注释

转载 作者:行者123 更新时间:2023-11-29 19:23:20 26 4
gpt4 key购买 nike

我正在尝试为多重调用构建一个接口(interface)。即 http://server.com/firstQuery http://server.com/secondQuery

这是我 retrofit 的rx接口(interface)

public interface RequestInterfaceRx<T> {
@GET("/")
Observable<CurrencyOnServerConstruct> register();
Call<ResponseBody> setUrl(@Url String url);
}

这是我使用的代码

private void setupQuery(){
RequestInterfaceRx requestInterface = new Retrofit.Builder()
.baseUrl("http://server.com/v3/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build().create(RequestInterfaceRx.class);
requestInterface.setUrl("m");
requestInterface.register()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(this::handleResponse,this::handleError);
}

它并没有像预期的那样真正起作用:)

        Caused by: java.lang.IllegalArgumentException: HTTP method annotation is required (e.g., @GET, @POST, etc.).
for method RequestInterfaceRx.setUrl
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:720)
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:711)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:174)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy0.setUrl(Unknown Source)
at bytesand.myapplicationaqueryserverrx.MainActivity.setupQuery(MainActivity.java:29)
at bytesand.myapplicationaqueryserverrx.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
... 9 more

最佳答案

@GET Observable<CurrencyOnServerConstruct> executeFullUrlCall(@Url String url); 

你就是这样做的

C 全文 https://medium.com/@sasa_sekulic/quick-and-easy-guide-to-retrofit-2-0-setup-or-migration-with-rxjava-ab7a11bc17df#.s5ifc5kov

关于android - RxJava 2 Retrofit 和动态 url 以及 @url 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41920114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com