retrofit2 不创建对象直接返回字符串

retrofit请求直接返回string

有个需求是直接用retrofit去get网页得到html,不创建对象。

用上面文章讲的方法,直接返回ResponseBody

ICollection:

public interface ICollection {

    @GET("/collection/{cid}")
Call<ResponseBody> getCollection(@Path("cid") String cid); }
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(new OkHttpClient())//不加转换器
.build();
ICollection iCollection = retrofit.create(ICollection.class);
Call<ResponseBody> call = iCollection.getCollection(ID);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) { try {
Message msg = Message.obtain();
msg.what = 1;
msg.obj = response.body().string();
handler.sendMessage(msg);
}
catch (IOException e){e.printStackTrace();}
} @Override
public void onFailure(Call<ResponseBody> call, Throwable t) { }
});
上一篇:《oracle每日一练》免安装Oracle客户端使用PL/SQL


下一篇:一个不安装Oracle客户端的方法------未经试验