使用步骤:
(1)导入依赖
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.0</version>
</dependency>
(2)java代码
String url = "http://192.168.200.128/ad_update?position="+position;
//创建okhttp对象,这个东西是目前最快的发送请求的中间件技术
OkHttpClient okHttpClient = new OkHttpClient();
//创建请求对象
Request request = new Request.Builder().url(url).build();
//发送请求
Call call = okHttpClient.newCall(request);
//调用发送请求后的回调方法,获取发送成功或者是失败的消息
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
System.out.println("=======发送失败========");
}
@Override
public void onResponse(Call call, Response response) throws IOException {
System.out.println("=======发送成功======"+response.message());
}
});