package com.example.zhoukao2.HTTP;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
public class OKHttp {
private static OkHttpClient okHttpClient;
private static Request build;
private static OkHttpClient okHttpClient1;
private static FormBody body;
private static Request builder;
public static void OkHttpDoGet(String url, Callback callback){
//获取请求的参数
okHttpClient = new OkHttpClient();
//请求的方式
build = new Request.Builder().url(url).get().build();
okHttpClient.newCall(build).enqueue(callback);
}
public static void OkHTTPPOst(String url,String name,String pwd,Callback callback){
okHttpClient1 = new OkHttpClient();
//Post需要创建Body 需要配置键值对
body = new FormBody.Builder().
add("phone", name)
.add("pwd", pwd)
.build();
//请求方式并且提交页面
builder = new Request.Builder().url(url).post(body).build();
//服务器返回的数据
okHttpClient1.newCall(builder).enqueue(callback);
}
}
OKHTTP
最新推荐文章于 2024-07-18 17:04:34 发布