改造动态 HTTP 方法 [英] Retrofit dynamic HTTP methods
问题描述
我计划在我的项目中用改造替换 Apache HTTP 客户端.我面临的问题是改造不(我找不到)支持在运行时设置 HTTP 方法来请求.在我的Web Service中我不知道提前调用什么HTTP方法,所以注释@GET,@POST,...没有用.
I'm planning to replace Apache HTTP client with retrofit in my project. The problem I'm facing is that retrofit didn't(I couldn't find) support setting HTTP method to request at runtime. In my Web Service I don't know what HTTP method to call in advance, so annotations @GET, @POST, ... are useless.
推荐答案
Retrofit 不是为动态 url 请求而设计的.您使用 API 基本 URL 配置改造,然后发出特定请求.
Retrofit is not designed for dynamic url requests. You configure retrofit with your API base URL then make specific requests.
要获得更灵活的动态选项,请使用 OkHttp.它是 Retrofit 使用的 HTTP 客户端,易于使用.
For a more flexible dynamic option use out OkHttp. It is the HTTP Client used by Retrofit and it easy to work with.
这篇关于改造动态 HTTP 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!