okhttp
public class HttpUtils { private static volatile HttpUtils instance; private final OkHttpClient client; private Handler handler = new Handler(); private HttpUtils(){ client = new OkHttpClient(); } public static HttpUtils getInstance(){ if (instance == null){ synchronized (HttpUtils.class){ if (null == instance){ instance = new HttpUtils(); } } } return instance; } public void get(String url, final ICallBack callBack, final Type type){ Request request = new Request.Builder().get() .url(url) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { callBack.failed(e); } }); } @Override public void onResponse(Call call, Response response) throws IOException { String result = response.body().string(); Gson gson = new Gson(); final Object o = gson.fromJson(result, type); handler.post(new Runnable() { @Override public void run() { callBack.success(o); } }); } }); } }
replace https为http
public class StringUtils { public static String https2Http(String url){ return url.replace("https","http"); } }