在RequestApi里加
@POST
Call<String> post(@Header("Authorization") String apikey,@Url String uri);
在 HttpUtils 里加
//post请求带请求头
public static void post(String apikey, boolean isReadCookie, boolean isSaveCookie, String baseUri, String uri, final Callback<String> callback) {
OkHttpClient httpClient = getOkHttClient(isReadCookie, isSaveCookie);
Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUri).client(httpClient).addConverterFactory(ScalarsConverterFactory.create()).build();
RequestAPI requestAPI = retrofit.create(RequestAPI.class);
requestAPI.post(apikey,uri).enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
callback.onResponse(call, response);
}
@Override
public void onFailure(Call<String> call, Throwable t) {
callback.onFailure(call, t);
}
});
}
在basedata里加
//post获取网络数据
public void post(String apikey,boolean isReadCookie, boolean isSaveCookie, final String baseUri, final String uri, final int time) {
HttpUtils.post(apikey,isReadCookie, isSaveCookie, baseUri, uri, new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
String s = response.body();
onSucesss(s);
}
@Override
public void onFailure(Call<String> call, Throwable t) {
onError(t);
}
});
}