Проблема с соединением OKHTTP3
Не получается получить данные с url Вот код:
class MainActivity : AppCompatActivity() {
lateinit var recyclerviewDetails: RecyclerView
var arrayListDetails: ArrayList<News> = ArrayList();
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
recyclerviewDetails = findViewById(R.id.recyclerViewNews)
run("http://188.40.167.45:3001")
val adapter: Adapter = Adapter()
recyclerviewDetails.adapter = adapter
}
private fun run(url: String) {
val client = OkHttpClient()
val request = Request.Builder()
.url(url)
.build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
override fun onResponse(call: Call, response: Response) {
if (!response.isSuccessful) {
throw IOException("Unexpected code " + response);
} else {
val strResponse = response.body!!.string()
val jsonContact: JSONObject = JSONObject(strResponse)
val size: Int = 5
arrayListDetails = ArrayList();
for (i in 0 until size) {
val jsonObjectDetail: JSONObject = jsonContact
val news: News = News()
news.title = jsonObjectDetail.getString("title")
news.type = jsonObjectDetail.getString("type")
news.img = jsonObjectDetail.getString("img")
news.clickUrl = jsonObjectDetail.getString("click_url")
news.time = jsonObjectDetail.getString("time")
news.top = jsonObjectDetail.getString("top")
arrayListDetails.add(news)
}
}
}
})
}
}
Вот ошибки в логе:
2020-09-21 20:32:58.152 13793-13793/? I/emo.gamenewsap: Not late-enabling -Xcheck:jni (already on)
2020-09-21 20:32:58.173 13793-13793/? E/emo.gamenewsap: Unknown bits set in runtime_flags: 0x8000
2020-09-21 20:32:58.175 13793-13793/? W/emo.gamenewsap: Unexpected CPU variant for X86 using defaults: x86
2020-09-21 20:32:58.423 13793-13827/com.demo.gamenewsapp D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2020-09-21 20:32:58.438 13793-13827/com.demo.gamenewsapp W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2020-09-21 20:32:58.415 13793-13793/com.demo.gamenewsapp W/RenderThread: type=1400 audit(0.0:51): avc: denied { write } for name="property_service" dev="tmpfs" ino=7421 scontext=u:r:untrusted_app:s0:c138,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2020-09-21 20:32:58.496 13793-13827/com.demo.gamenewsapp D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-09-21 20:32:58.502 13793-13827/com.demo.gamenewsapp D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-09-21 20:32:58.509 13793-13827/com.demo.gamenewsapp D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-09-21 20:32:58.628 13793-13793/com.demo.gamenewsapp D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2020-09-21 20:32:58.701 13793-13793/com.demo.gamenewsapp W/emo.gamenewsap: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2020-09-21 20:32:58.702 13793-13793/com.demo.gamenewsapp W/emo.gamenewsap: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2020-09-21 20:32:58.848 13793-13825/com.demo.gamenewsapp D/HostConnection: HostConnection::get() New Host Connection established 0xd3981e60, tid 13825
2020-09-21 20:32:58.848 13793-13825/com.demo.gamenewsapp 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_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
2020-09-21 20:32:58.850 13793-13793/com.demo.gamenewsapp E/RecyclerView: No adapter attached; skipping layout
2020-09-21 20:32:58.851 13793-13825/com.demo.gamenewsapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2020-09-21 20:32:58.855 13793-13825/com.demo.gamenewsapp D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2020-09-21 20:32:58.855 13793-13825/com.demo.gamenewsapp D/EGL_emulation: eglCreateContext: 0xdf015800: maj 3 min 0 rcv 3
2020-09-21 20:32:58.866 13793-13825/com.demo.gamenewsapp D/EGL_emulation: eglMakeCurrent: 0xdf015800: ver 3 0 (tinfo 0xdf0f5e40)
2020-09-21 20:32:58.883 13793-13825/com.demo.gamenewsapp W/Gralloc3: mapper 3.x is not supported
2020-09-21 20:32:58.886 13793-13825/com.demo.gamenewsapp D/HostConnection: createUnique: call
2020-09-21 20:32:58.886 13793-13825/com.demo.gamenewsapp D/HostConnection: HostConnection::get() New Host Connection established 0xd3983c60, tid 13825
2020-09-21 20:32:58.888 13793-13825/com.demo.gamenewsapp 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_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
2020-09-21 20:32:58.888 13793-13825/com.demo.gamenewsapp D/eglCodecCommon: allocate: Ask for block of size 0x1000
2020-09-21 20:32:58.888 13793-13825/com.demo.gamenewsapp D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ffff6000 size 0x2000
2020-09-21 20:32:58.915 13793-13825/com.demo.gamenewsapp D/EGL_emulation: eglMakeCurrent: 0xdf015800: ver 3 0 (tinfo 0xdf0f5e40)
2020-09-21 20:32:58.917 13793-13825/com.demo.gamenewsapp D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
2020-09-21 20:32:59.018 13793-13828/com.demo.gamenewsapp W/System.err: javax.net.ssl.SSLHandshakeException: Handshake failed
2020-09-21 20:32:59.019 13793-13828/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:288)
2020-09-21 20:32:59.019 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.kt:379)
2020-09-21 20:32:59.019 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.kt:337)
2020-09-21 20:32:59.020 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:209)
2020-09-21 20:32:59.020 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
2020-09-21 20:32:59.020 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
2020-09-21 20:32:59.020 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
2020-09-21 20:32:59.020 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
2020-09-21 20:32:59.020 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
2020-09-21 20:32:59.021 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:32:59.021 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
2020-09-21 20:32:59.021 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:32:59.021 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
2020-09-21 20:32:59.021 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:32:59.021 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
2020-09-21 20:32:59.022 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:32:59.022 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
2020-09-21 20:32:59.022 13793-13828/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
2020-09-21 20:32:59.022 13793-13828/com.demo.gamenewsapp W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2020-09-21 20:32:59.022 13793-13828/com.demo.gamenewsapp W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2020-09-21 20:32:59.022 13793-13828/com.demo.gamenewsapp W/System.err: at java.lang.Thread.run(Thread.java:919)
2020-09-21 20:32:59.023 13793-13828/com.demo.gamenewsapp W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xd6f67548: Failure in SSL library, usually a protocol error
2020-09-21 20:32:59.023 13793-13828/com.demo.gamenewsapp W/System.err: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.cc:242 0xd1480543:0x00000000)
2020-09-21 20:32:59.024 13793-13828/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
2020-09-21 20:32:59.024 13793-13828/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.NativeSsl.doHandshake(NativeSsl.java:387)
2020-09-21 20:32:59.024 13793-13828/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:226)
2020-09-21 20:32:59.024 13793-13828/com.demo.gamenewsapp W/System.err: ... 20 more
2020-09-21 20:37:45.360 13793-13825/com.demo.gamenewsapp D/EGL_emulation: eglMakeCurrent: 0xdf015800: ver 3 0 (tinfo 0xdf0f5e40)
2020-09-21 20:38:49.109 13793-14356/com.demo.gamenewsapp W/System.err: javax.net.ssl.SSLHandshakeException: Handshake failed
2020-09-21 20:38:49.109 13793-14356/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:288)
2020-09-21 20:38:49.109 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.kt:379)
2020-09-21 20:38:49.109 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.kt:337)
2020-09-21 20:38:49.109 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:209)
2020-09-21 20:38:49.109 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
2020-09-21 20:38:49.109 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
2020-09-21 20:38:49.110 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
2020-09-21 20:38:49.110 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
2020-09-21 20:38:49.110 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
2020-09-21 20:38:49.110 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:38:49.110 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
2020-09-21 20:38:49.110 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:38:49.110 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
2020-09-21 20:38:49.111 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:38:49.111 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
2020-09-21 20:38:49.111 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at java.lang.Thread.run(Thread.java:919)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xd6f69688: Failure in SSL library, usually a protocol error
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.cc:242 0xd1480543:0x00000000)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.NativeSsl.doHandshake(NativeSsl.java:387)
2020-09-21 20:38:49.112 13793-14356/com.demo.gamenewsapp W/System.err: at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:226)
2020-09-21 20:38:49.113 13793-14356/com.demo.gamenewsapp W/System.err: ... 20 more
2020-09-21 20:38:55.149 13793-13793/com.demo.gamenewsapp E/RecyclerView: No adapter attached; skipping layout
2020-09-21 20:38:55.180 13793-13825/com.demo.gamenewsapp D/EGL_emulation: eglMakeCurrent: 0xdf015800: ver 3 0 (tinfo 0xdf0f5e40)