2021-12-03

Android Studio HttpURLConnection.getResponseCode() is throwin IO Exception

I am new at android studio and I need to make an http request to my api. I am sure that my api is working properly. When I debbugig

int responseCode = connection.getResponseCode();

is throiwn IO Exception directly, everytime. My all code is:

public void makeRequest(){

    try {
        HttpURLConnection connection;
        URL url = new URL("https://34.141.39.66:8000/api");
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.connect();

        int responseCode = connection.getResponseCode();

        
        
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

}

and logcat says:

2021-12-02 22:12:17.244 10182-10182/? I/com.example.kb: Late-enabling -Xcheck:jni 2021-12-02 22:12:17.289 10182-10182/? E/com.example.kb: Unknown bits set in runtime_flags: 0x8000 2021-12-02 22:12:17.289 10182-10182/? W/com.example.kb: Unexpected CPU variant for X86 using defaults: x86 2021-12-02 22:12:17.461 10182-10182/com.example.kbc W/ActivityThread: Application com.example.kbc is waiting for the debugger on port 8100... 2021-12-02 22:12:17.491 10182-10182/com.example.kbc I/System.out: Sending WAIT chunk 2021-12-02 22:12:18.321 10182-10182/com.example.kbc I/System.out: Debugger has connected 2021-12-02 22:12:18.321 10182-10182/com.example.kbc I/System.out: waiting for debugger to settle... 2021-12-02 22:12:18.742 10182-10182/com.example.kbc I/chatty: uid=10134(com.example.kbc) identical 2 lines 2021-12-02 22:12:18.951 10182-10182/com.example.kbc I/System.out: waiting for debugger to settle... 2021-12-02 22:12:19.163 10182-10182/com.example.kbc I/System.out: waiting for debugger to settle... 2021-12-02 22:12:19.372 10182-10182/com.example.kbc I/System.out: waiting for debugger to settle... 2021-12-02 22:12:19.581 10182-10182/com.example.kbc I/System.out: waiting for debugger to settle... 2021-12-02 22:12:19.783 10182-10182/com.example.kbc I/System.out: debugger has settled (1382) 2021-12-02 22:12:20.023 10182-10233/com.example.kbc D/libEGL: Emulator has host GPU support, qemu.gles is set to 1. 2021-12-02 22:12:20.020 10182-10182/com.example.kbc W/RenderThread: type=1400 audit(0.0:55): avc: denied { write } for name="property_service" dev="tmpfs" ino=7346 scontext=u:r:untrusted_app:s0:c134,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 2021-12-02 22:12:20.024 10182-10233/com.example.kbc W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied) 2021-12-02 22:12:20.037 10182-10233/com.example.kbc D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so 2021-12-02 22:12:20.038 10182-10233/com.example.kbc D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2021-12-02 22:12:20.040 10182-10233/com.example.kbc D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so 2021-12-02 22:12:20.376 10182-10182/com.example.kbc W/com.example.kb: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2021-12-02 22:12:20.376 10182-10182/com.example.kbc W/com.example.kb: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2021-12-02 22:12:20.532 10182-10182/com.example.kbc D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2021-12-02 22:12:22.378 10182-10182/com.example.kbc W/com.example.kb: Got a deoptimization request on un-deoptimizable method java.io.FileDescriptor libcore.io.Linux.socket(int, int, int) 2021-12-02 22:12:24.138 10182-10182/com.example.kbc D/msg:: socket failed: EPERM (Operation not permitted)

How can I solve it? Thank you!



from Recent Questions - Stack Overflow https://ift.tt/3Ijasx8
https://ift.tt/eA8V8J

No comments:

Post a Comment