package com.example.Utils;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class HttpUtils {
private static HttpUtils httpUtils = new HttpUtils();
public HttpUtils() {
}
public static HttpUtils getHttpUtils() {
synchronized (httpUtils)
{
if (httpUtils == null)
{
httpUtils = new HttpUtils();
}
return httpUtils;
}
}
public String get(String urlString) {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().url(urlString).get().build();
try {
Response response = okHttpClient.newCall(request).execute();
return response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
HttpUtils工具类 采用Okhttp获取网络数据
最新推荐文章于 2024-09-05 15:52:51 发布