安卓HttpURLConne报错/NetworkSecurityConfig: No Network Security Config specified, using platform default

博客内容讲述了在Android应用中遇到未使用HTTPS协议的URL导致的网络错误,通过创建一个XML文件并设置`<base-config cleartextTrafficPermitted=true/>`允许明文流量,然后在Manifest中引用该XML,成功解决了问题。
这是我没有使用https协议的链接
URL url = new URL("http://192.168.43.128:8080/VaccinDemo/record/list");//
报错截图:

解决方法:

编写一个xml文件:

内容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

然后在mainfest里面引用:

     android:networkSecurityConfig="@xml/network"

如图:

问题解决!

 

06/02 13:06:49: Launching 'app' on Pixel 2 API 30. $ adb shell am start -n "net.hnjdzy.wujiajia.aysnctaskdemo56/net.hnjdzy.wujiajia.aysnctaskdemo56.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Connected to process 16851 on device 'emulator-5554'. Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. I/aysnctaskdemo5: Late-enabling -Xcheck:jni I/aysnctaskdemo5: Unquickening 12 vdex files! W/aysnctaskdemo5: Unexpected CPU variant for X86 using defaults: x86 D/NetworkSecurityConfig: No Network Security Config specified, using platform default D/NetworkSecurityConfig: No Network Security Config specified, using platform default D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so W/aysnctaskdemo5: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) W/aysnctaskdemo5: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) E/NetworkRequest: Error: Cleartext HTTP traffic to 220.181.38.148 not permitted D/NetworkRequest: Result: Error: Cleartext HTTP traffic to 220.181.38.148 not permitted D/HostConnection: HostConnection::get() New Host Connection established 0xeb66fb80, tid 16899 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... D/EGL_emulation: eglCreateContext: 0xeb6707c0: maj 2 min 0 rcv 2 D/EGL_emulation: eglMakeCurrent: 0xeb6707c0: ver 2 0 (tinfo 0xeb9b8190) (first time) I/Gralloc4: mapper 4.x is not supported D/HostConnection: createUnique: call D/HostConnection: HostConnection::get() New Host Connection established 0xeb670ad0, tid 16899 D/goldfish-address-space: allocate: Ask for block of size 0x100 D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3f3ffe000 size 0x2000 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2
最新发布
06-03
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值