有个需求是直接用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) { }
});