koush / ion

Android Asynchronous Networking and Image Loading
Other
6.3k stars 1.04k forks source link

Gives 200 response code instead of 404 for file not found #868

Open Sp4Rx opened 6 years ago

Sp4Rx commented 6 years ago

Here is my code for Ion

 Ion.with(getApplicationContext())
            .load("http://192.168.1.117/temp_cbtserver/biometric/AE13762513.min1")
            .asString()
            .withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    Log.d(TAG, "##:code: " + result.getHeaders().code());
                    Log.d(TAG, "##:message: " + result.getHeaders().message());

                    if (e == null) {
                        Log.d(TAG, "##:Response: \n" + result.getResult());
                    } else {
                        if (BuildConfig.DEBUG)
                            e.printStackTrace();
                    }
                }
            });

This url http://192.168.1.117/temp_cbtserver/biometric/AE13762513.min1 does not exist so it should return 404 code but its returning 200 along with the File not found html message as the response. Check the log message below.

02-16 12:57:31.417 3162-3162/manager.attendance.com D/SaveAttendance: ##:code: 200
02-16 12:57:31.418 3162-3162/manager.attendance.com D/SaveAttendance: ##:message: OK
02-16 12:57:31.418 3162-3162/manager.attendance.com D/SaveAttendance: ##:Response: 
                                                                  <!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>vue-exam-panel</title><link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons" rel=stylesheet type=text/css><link href=/static/css/app.baf12460d660f35d8efedc2ffe9327f5.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.b8d004f8dfcd7d197ec7.js></script><script type=text/javascript src=/static/js/vendor.c7bd4c75680f647b621e.js></script><script type=text/javascript src=/static/js/app.15ea6408e5f640cec760.js></script></body></html>

This is how the html response looks like. Error 404

I have also tested the same url using volley, it gave 404 which is correct. Check the volley response below.

02-16 12:53:57.668 2447-2891/manager.attendance.com E/Volley: [23330] BasicNetwork.performRequest: Unexpected response code 404 for http://192.168.1.117/temp_cbtserver/biometric/AE13762513.min1
02-16 12:53:57.669 2447-2447/manager.attendance.com D/SaveAttendance: ##:code: 404
02-16 12:53:57.669 2447-2447/manager.attendance.com D/SaveAttendance: ##:headers: {Accept-Ranges=bytes, Connection=Keep-Alive, Content-Language=en, Content-Type=text/html; charset=utf-8, Date=Fri, 16 Feb 2018 07:24:08 GMT, Keep-Alive=timeout=5, max=100, Server=Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/7.1.4, Transfer-Encoding=chunked, Vary=accept-language,accept-charset, X-Android-Received-Millis=1518765837663, X-Android-Response-Source=NETWORK 404, X-Android-Selected-Protocol=http/1.1, X-Android-Sent-Millis=1518765837628}
fukhaos commented 5 years ago

+1

ironjan commented 4 years ago

I tried the above code for the url https://en.m.wikipedia.org/wiki/List_of_HTTP_status_codes/does-not-exist and received the expected 404.

Can you verify if this issue still exists with the newest version of ion?