App防网络请求被代理抓包

判断手机是否有设置代理

    public static boolean checkWifiProxy(Context context) {
        if (!isWifi(context)) {
            return false;
        }
        String proxyAddress = System.getProperty("http.proxyHost");
        int proxyPort = NumberUtil.toInt(System.getProperty("http.proxyPort"), -1);
        boolean hasProxy = !TextUtils.isEmpty(proxyAddress) && proxyPort != -1;
        if (hasProxy) {
            Log.d("proxyAddress=" + proxyAddress + "; proxyPort=" + proxyPort);
        }
        return hasProxy;
    }

通过简单的设置就可以防止被网络代理抓包,

OKHttp可以设置Proxy.NO_PROXY来屏蔽系统代理

OkHttpClient.Builder().proxy(Proxy.NO_PROXY);

Volley可通过下方代码进行设置

public class ProxiedHurlStack extends HurlStack {
    @Override
    protected HttpURLConnection createConnection(URL url) throws IOException {
        return (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
    }
}

你可能感兴趣的:(App防网络请求被代理抓包)