.get()
.url(NetApi.BASE_URL_START + BaseApplication.getmIp() + NetApi.BASE_URL_END + url)
.addHeader(headerMap)
.addParam(map)
.execeute(callBack);
- 绕过证书认证
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/**
- 绕过所有的证书
*/
public class TrustAllCerts implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public static SSLSocketFactory createSSLSocketFactory() {
SSLSocketFactory factory = null;
try {
SSLContext context = SSLContext.getInstance(“TLS”);
context.init(null, new TrustManager[]{new TrustAllCerts()}, new SecureRandom());
factory = context.getSocketFactory();
} catch (Exception e) {
}
return factory;
}
public static class TrustAllHostnameVerifier implements HostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
}
private static OkHttpClient mOkHttpClient = new OkHttpClient()
.newBuilder()
.sslSocketFactory(TrustAllCerts.createSSLSocketFactory())
.hostnameVerifier(new TrustAllCerts.TrustAllHostnameVerifier())
.build();
使用sslSocketFactory和hostnameVerifier绕过证书认证
- 封装好的 OkHttp引擎
import android.content.Context;
import java.io.File;
import java.io.IOException;
import java.net.FileNameMap;
import java.net.Proxy;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import tsou.cn.lib_hxgokhttp.IHttpEngine;
import tsou.cn.lib_hxgokhttp.URLUtil;
import tsou.cn.lib_hxgokhttp.callback.EngineCallBack;
import tsou.cn.lib_hxgokhttp.interceptor.LogInterceptor;
/**
-
Created by Administrator on 2018/7/19 0019.
-
封装OkHttp默认引擎
*/
public class OkHttpEngine implements IHttpEngine {
private static OkHttpClient mOkHttpClient = new OkHttpClient()
.newBuilder()
.sslSocketFactory(TrustAllCerts.createSSLSocketFactory())
.addInterceptor(new LogInterceptor())
.hostnameVerifier(new TrustAllCerts.TrustAllHostnameVerifier())
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(20, TimeUnit.SECONDS)
.readTimeout(20, TimeUnit.SECONDS)
.pingInterval(20, TimeUnit.SECONDS)
.proxy(Proxy.NO_PROXY)
.build();
public static void cancelTag(Object tag) {
for (Call call : mOkHttpClient.dispatcher().queuedCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
}
}
for (Call call : mOkHttpClient.dispatcher().runningCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
}
}
}
public static void callAll() {
mOkHttpClient.dispatcher().cancelAll();
}
public static void init(OkHttpClient okHttpClient) {
mOkHttpClient = okHttpClient;
}
@Override
public void get(Context context, String url, Map<String, Object> header,
Map<String, Object> params, final EngineCallBack callBack) {
String jointUrl = URLUtil.jointParams(url, params);
Request.Builder requestBuilder = new Request.Builder()
.url(jointUrl)
.tag(context);
if (header != null && header.size() > 0) {
for (Map.Entry<String, Object> entry : header.entrySet()) {
requestBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
}
}
callBack.onBefore(context);
Request request = requestBuilder.build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
callBack.onAfter();
callBack.onError(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
callBack.onAfter();
ResponseBody responseBody = response.body();
callBack.onSuccess(responseBody);
}
});
}
@Override
public void post(Context context, String url, Map<String, Object> header, Map<String, Object> params,
final EngineCallBack callBack) {
RequestBody requestBody = appendBody(params);
Request.Builder requestBuilder = new Request.Builder()
.url(url)
.tag(context);
if (header != null && header.size() > 0) {
for (Map.Entry<String, Object> entry : header.entrySet()) {
requestBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
}
}
Request request = requestBuilder
.post(requestBody)
.build();
callBack.onBefore(context);
mOkHttpClient.newCall(request).enqueue(
new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
callBack.onAfter();
callBack.onError(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
callBack.onAfter();
ResponseBody responseBody = response.body();
callBack.onSuccess(responseBody);
}
}
);
}
@Override
public void put(Context context, String url, Map<String, Object> header, Map<String, Object> params, final EngineCallBack callBack) {
RequestBody requestBody = appendBody(params);
Request.Builder requestBuilder = new Request.Builder()
.url(url)
.tag(context);
if (header != null && header.size() > 0) {
for (Map.Entry<String, Object> entry : header.entrySet()) {
requestBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
}
}
Request request = requestBuilder
.put(requestBody)
.build();
callBack.onBefore(context);
mOkHttpClient.newCall(request).enqueue(
new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
callBack.onAfter();
callBack.onError(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
callBack.onAfter();
ResponseBody responseBody = response.body();
callBack.onSuccess(responseBody);
}
}
);
}
@Override
public void delete(Context context, String url, Map<String, Object> header, Map<String, Object> params, final EngineCallBack callBack) {
RequestBody requestBody = appendBody(params);
Request.Builder requestBuilder = new Request.Builder()
.url(url)
.tag(context);
if (header != null && header.size() > 0) {
for (Map.Entry<String, Object> entry : header.entrySet()) {
requestBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
}
}
Request request = requestBuilder
.delete(requestBody)
.build();
callBack.onBefore(context);
mOkHttpClient.newCall(request).enqueue(
new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
callBack.onAfter();
callBack.onError(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
callBack.onAfter();
ResponseBody responseBody = response.body();
callBack.onSuccess(responseBody);
}
}
);
}
@Override
public void post(Context context, String url, Map<String, Object> header, String json, final EngineCallBack callBack) {
MediaType mediaType = MediaType.parse(“application/xml; charset=utf-8”);//“类型,字节码”
RequestBody requestBody = RequestBody.create(mediaType, json);
Request.Builder requestBuilder = new Request.Builder()
.url(url)
.tag(context);
if (header != null && header.size() > 0) {
for (Map.Entry<String, Object> entry : header.entrySet()) {
requestBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
}
}
Request request = requestBuilder
.post(requestBody)
.build();
callBack.onBefore(context);
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
callBack.onAfter();
callBack.onError(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
callBack.onAfter();
ResponseBody responseBody = response.body();
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
![](https://i-blog.csdnimg.cn/blog_migrate/670a046b2c660be4707c920d064b1cee.jpeg)
最后
上面这些公司都是时下最受欢迎的互联网大厂,他们的职级、薪资、福利也都讲的差不多了,相信大家都是有梦想和野心的人,心里多少应该都有些想法。
也相信很多人也都在为即将到来的金九银十做准备,也有不少人的目标都是这些公司。
我这边有不少朋友都在这些厂工作,其中也有很多人担任过面试官,上面的资料也差不多都是从朋友那边打探来的。除了上面的信息,我这边还有这些大厂近年来的面试真题及解析,以及一些朋友出于兴趣和热爱一起整理的Android时下热门知识点的学习资料。
部分文件:
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
讲解视频,并且会持续更新!**
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
![](https://i-blog.csdnimg.cn/blog_migrate/670a046b2c660be4707c920d064b1cee.jpeg)
最后
上面这些公司都是时下最受欢迎的互联网大厂,他们的职级、薪资、福利也都讲的差不多了,相信大家都是有梦想和野心的人,心里多少应该都有些想法。
也相信很多人也都在为即将到来的金九银十做准备,也有不少人的目标都是这些公司。
我这边有不少朋友都在这些厂工作,其中也有很多人担任过面试官,上面的资料也差不多都是从朋友那边打探来的。除了上面的信息,我这边还有这些大厂近年来的面试真题及解析,以及一些朋友出于兴趣和热爱一起整理的Android时下热门知识点的学习资料。
部分文件:
[外链图片转存中…(img-RqfbFN7k-1712680081096)]
[外链图片转存中…(img-ckGoPpue-1712680081096)]
[外链图片转存中…(img-gAZZYtbk-1712680081096)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!