拦截器没搞懂就先搞这个法子暂时先写到请求里面,不然api接口啥都用不了,其实也并不是特别麻烦,后续要改,不考虑使用拦截器的话,可能要使用到sqlite
数据库,emmmm,想想还是别这么干
public void postTest(){
OkHttpClient client = new OkHttpClient();
//post请求
FormBody formBody = new FormBody.Builder()
.add("event_id","33")
.build();
Request request = new Request.Builder().url(DecryptionAddress+"app/event/accept").
addHeader("Token","服务器获取的token").post(formBody).build();
client.newCall(request).enqueue(new Callback() {
public void onFailure(Call call, IOException e) {
System.out.println(e.getMessage());
}
public void onResponse(Call call, Response response) throws IOException {
if(response.code() >= 200 && response.code() < 300) {
String result = response.body().string();
System.out.println(result);
}
}
});
}
public void getTest(){
//get请求
OkHttpClient client = new OkHttpClient();
Request request1 = new Request.Builder()
.url(DecryptionAddress+"/app/event/detail?event_id=89")
.addHeader("Token","服务器获取的token")
.build();
client.newCall(request1).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
System.out.println(e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if(response.code() >= 200 && response.code() < 300) {
String result = response.body().string();
System.out.println(result);
}
}
});
}
版权说明
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!