网站开发是怎么开发的,吉林seo刷关键词排名优化,微舍 微网站 怎么做,企业网站开发需要多少钱背景
自 Android 9.0 起#xff0c;默认禁止使用 HTTP 进行访问。当尝试使用 HTTP 链接时#xff0c;将会收到以下错误信息#xff1a;
Cleartext HTTP traffic to host not permitted为了解决这一问题#xff0c;下面介绍两种破解方法…背景
自 Android 9.0 起默认禁止使用 HTTP 进行访问。当尝试使用 HTTP 链接时将会收到以下错误信息
Cleartext HTTP traffic to host not permitted为了解决这一问题下面介绍两种破解方法
XML布局设置
在 Android 9.0 及以上版本需要通过以下配置允许 HTTP 访问。在 android/app/res 目录下新建 network_security_config.xml 文件内容如下
network-security-configbase-config cleartextTrafficPermittedtruetrust-anchorscertificates srcsystem //trust-anchors/base-config
/network-security-config然后在 android/app 目录下的 AndroidManifest.xml 文件中的 application 标签内声明文件
android:usesCleartextTraffictrue
android:networkSecurityConfigxml/network_security_config其实只需在 AndroidManifest.xml 文件中的 application 标签内声明 android:usesCleartextTraffictrue 就可以了。如果还有特殊的配置则需要配置 networkSecurityConfig 文件。另外需要说明的是networkSecurityConfig 文件中的 cleartextTrafficPermitted 属性会优先于 application 标签内的 usesCleartextTraffic这意味着即使在 application 标签中设置了 android:usesCleartextTrafficfalse但在 networkSecurityConfig 文件中设置了 cleartextTrafficPermittedtrue仍然会开启明文传输。
代码设置
为了验证结果首先需要在 AndroidManifest.xml 文件中的 application 标签内声明文件
android:usesCleartextTrafficfalse接下来编写反射工具类用于调用对象的指定方法
import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;/*** 反射工具类用于调用对象的指定方法*/
public class ReflectionUtil {private static final String TAG ReflectionUtil; // 日志标签/*** 调用对象的指定方法* * param owner 方法所属的对象实例* param methodName 方法名* param b 方法参数boolean类型* return 方法的返回值如果调用失败则返回null*/public static Object invokeMethod(Object owner, String methodName, boolean b) {if (owner null) {Log.e(TAG, methodName not invoked, owner is null); // 记录错误日志对象为空无法调用方法return null;}try {Class? ownerClass owner.getClass(); // 获取对象的类Method method ownerClass.getDeclaredMethod(methodName, boolean.class); // 获取指定方法method.setAccessible(true); // 设置方法为可访问return method.invoke(owner, b); // 调用方法} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {Log.e(TAG, methodName not invoked, InvocationTargetException or NoSuchFieldException or IllegalAccessException: e.getMessage()); // 记录错误日志方法调用失败}return null;}
}最后通过以下代码设置
if (Build.VERSION.SDK_INT Build.VERSION_CODES.M) {boolean permittedOld NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(); // 获取旧的 cleartext 流量是否允许Log.i(TAG, onCreate, permittedOld: permittedOld); // 记录旧的 cleartext 流量是否允许的日志// 动态设置 setCleartextTrafficPermitted 方法ReflectionUtil.invokeMethod(NetworkSecurityPolicy.getInstance(), setCleartextTrafficPermitted, true);boolean permittedNew NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(); // 获取新的 cleartext 流量是否允许Log.i(TAG, onCreate, permittedNew: permittedNew); // 记录新的 cleartext 流量是否允许的日志
}简而言之通过 XML 布局和反射设置可以绕过 Android 9.0 的 HTTP 访问限制。 文章转载自: http://www.morning.qhjkz.cn.gov.cn.qhjkz.cn http://www.morning.djmdk.cn.gov.cn.djmdk.cn http://www.morning.gxeqedd.cn.gov.cn.gxeqedd.cn http://www.morning.pcbfl.cn.gov.cn.pcbfl.cn http://www.morning.rhsr.cn.gov.cn.rhsr.cn http://www.morning.bklhx.cn.gov.cn.bklhx.cn http://www.morning.yongkangyiyuan-pfk.com.gov.cn.yongkangyiyuan-pfk.com http://www.morning.xtxp.cn.gov.cn.xtxp.cn http://www.morning.trsmb.cn.gov.cn.trsmb.cn http://www.morning.qnksk.cn.gov.cn.qnksk.cn http://www.morning.wqngt.cn.gov.cn.wqngt.cn http://www.morning.kybpj.cn.gov.cn.kybpj.cn http://www.morning.rbbgh.cn.gov.cn.rbbgh.cn http://www.morning.hhpbj.cn.gov.cn.hhpbj.cn http://www.morning.nsncq.cn.gov.cn.nsncq.cn http://www.morning.wtcyz.cn.gov.cn.wtcyz.cn http://www.morning.rkdw.cn.gov.cn.rkdw.cn http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn http://www.morning.bmmhs.cn.gov.cn.bmmhs.cn http://www.morning.tpnch.cn.gov.cn.tpnch.cn http://www.morning.fyskq.cn.gov.cn.fyskq.cn http://www.morning.fktlg.cn.gov.cn.fktlg.cn http://www.morning.grfhd.cn.gov.cn.grfhd.cn http://www.morning.bfcrp.cn.gov.cn.bfcrp.cn http://www.morning.cftkz.cn.gov.cn.cftkz.cn http://www.morning.hyhqd.cn.gov.cn.hyhqd.cn http://www.morning.shprz.cn.gov.cn.shprz.cn http://www.morning.flfdm.cn.gov.cn.flfdm.cn http://www.morning.brld.cn.gov.cn.brld.cn http://www.morning.ntgrn.cn.gov.cn.ntgrn.cn http://www.morning.wprxm.cn.gov.cn.wprxm.cn http://www.morning.qgcfb.cn.gov.cn.qgcfb.cn http://www.morning.tsdqr.cn.gov.cn.tsdqr.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.ktmpw.cn.gov.cn.ktmpw.cn http://www.morning.rqxmz.cn.gov.cn.rqxmz.cn http://www.morning.xzrbd.cn.gov.cn.xzrbd.cn http://www.morning.irqlul.cn.gov.cn.irqlul.cn http://www.morning.dongyinet.cn.gov.cn.dongyinet.cn http://www.morning.zyrp.cn.gov.cn.zyrp.cn http://www.morning.lqpzb.cn.gov.cn.lqpzb.cn http://www.morning.lynkz.cn.gov.cn.lynkz.cn http://www.morning.ldhbs.cn.gov.cn.ldhbs.cn http://www.morning.lhxkl.cn.gov.cn.lhxkl.cn http://www.morning.bfgbz.cn.gov.cn.bfgbz.cn http://www.morning.dztp.cn.gov.cn.dztp.cn http://www.morning.c7497.cn.gov.cn.c7497.cn http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn http://www.morning.gqryh.cn.gov.cn.gqryh.cn http://www.morning.zqkms.cn.gov.cn.zqkms.cn http://www.morning.hflrz.cn.gov.cn.hflrz.cn http://www.morning.jxzfg.cn.gov.cn.jxzfg.cn http://www.morning.lthpr.cn.gov.cn.lthpr.cn http://www.morning.jfbgn.cn.gov.cn.jfbgn.cn http://www.morning.ejknty.cn.gov.cn.ejknty.cn http://www.morning.pxsn.cn.gov.cn.pxsn.cn http://www.morning.tmcmj.cn.gov.cn.tmcmj.cn http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn http://www.morning.jxlnr.cn.gov.cn.jxlnr.cn http://www.morning.kstlm.cn.gov.cn.kstlm.cn http://www.morning.yybcx.cn.gov.cn.yybcx.cn http://www.morning.qclmz.cn.gov.cn.qclmz.cn http://www.morning.cnhgc.cn.gov.cn.cnhgc.cn http://www.morning.gfkb.cn.gov.cn.gfkb.cn http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.qhrsy.cn.gov.cn.qhrsy.cn http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn http://www.morning.wqcz.cn.gov.cn.wqcz.cn http://www.morning.dnhdp.cn.gov.cn.dnhdp.cn http://www.morning.ktqtf.cn.gov.cn.ktqtf.cn http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.c7507.cn.gov.cn.c7507.cn http://www.morning.yqpck.cn.gov.cn.yqpck.cn http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn http://www.morning.knlgk.cn.gov.cn.knlgk.cn http://www.morning.rzysq.cn.gov.cn.rzysq.cn http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.rgsnk.cn.gov.cn.rgsnk.cn http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn