How to deal with unexpected response 500 in Android









up vote
0
down vote

favorite












I am trying to retrieve a JSON from an external API using Volley.
Here is my code



 protected void onCreate(Bundle savedInstanceState) 
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
final TextView mTextView = findViewById(R.id.testreq);
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
@Override
public void onResponse(String response)
// Display the first 500 characters of the response string.
mTextView.setText("Response is: "+ response.substring(0,500));

, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
mTextView.setText("That didn't work");
Log.d("Error", error.toString());

);
queue.add(stringRequest);



It seems like the response is done but I am getting this error




E/Volley: [277] BasicNetwork.performRequest: Unexpected response code 500
and when I ran a test on the API in https://apitester.com/ It tells me its passed and I get this error




Response Headers
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Sat, 10 Nov 2018 19:56:18 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json
Via: 1.1 vegur



Any ideas how to solve this? Is it the API or is it me?










share|improve this question





















  • @PushpeshKumarRajwanshi I do understand that status 500 means thats server error, and thats why I am asking if its me not handling the request properly or no. I wasnt going to ask if I didnt check my code already and couldnt figure it out. If theres nothing you can suggest why bother writing at all?
    – redberry
    Nov 10 at 20:22










  • I just tried accessing the URL you mentioned in your post and I am getting success response. So your problem hasn't reproduced to me. Can you try and check yourself again? May be server had some temporary problems, which got resolved. And now I can surely say, you don't have to fix anything at your end. Initially I thought may be you didn't pass some parameter or request body properly which might have resulted into this error, but that's not the case here as its a simple GET URL which needs no special headers/cookies/parameters. Sorry for the confusion and any inconvenience caused.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:28











  • That's the thing, the URL works well in browser, however when it comes to getting a response it fails with this code
    – redberry
    Nov 10 at 20:36










  • I just tried from code as well and I got the response successfully even from code. So seems like there is some silly mistake at your end only.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:39










  • Can you post your code?
    – redberry
    Nov 10 at 20:41














up vote
0
down vote

favorite












I am trying to retrieve a JSON from an external API using Volley.
Here is my code



 protected void onCreate(Bundle savedInstanceState) 
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
final TextView mTextView = findViewById(R.id.testreq);
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
@Override
public void onResponse(String response)
// Display the first 500 characters of the response string.
mTextView.setText("Response is: "+ response.substring(0,500));

, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
mTextView.setText("That didn't work");
Log.d("Error", error.toString());

);
queue.add(stringRequest);



It seems like the response is done but I am getting this error




E/Volley: [277] BasicNetwork.performRequest: Unexpected response code 500
and when I ran a test on the API in https://apitester.com/ It tells me its passed and I get this error




Response Headers
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Sat, 10 Nov 2018 19:56:18 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json
Via: 1.1 vegur



Any ideas how to solve this? Is it the API or is it me?










share|improve this question





















  • @PushpeshKumarRajwanshi I do understand that status 500 means thats server error, and thats why I am asking if its me not handling the request properly or no. I wasnt going to ask if I didnt check my code already and couldnt figure it out. If theres nothing you can suggest why bother writing at all?
    – redberry
    Nov 10 at 20:22










  • I just tried accessing the URL you mentioned in your post and I am getting success response. So your problem hasn't reproduced to me. Can you try and check yourself again? May be server had some temporary problems, which got resolved. And now I can surely say, you don't have to fix anything at your end. Initially I thought may be you didn't pass some parameter or request body properly which might have resulted into this error, but that's not the case here as its a simple GET URL which needs no special headers/cookies/parameters. Sorry for the confusion and any inconvenience caused.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:28











  • That's the thing, the URL works well in browser, however when it comes to getting a response it fails with this code
    – redberry
    Nov 10 at 20:36










  • I just tried from code as well and I got the response successfully even from code. So seems like there is some silly mistake at your end only.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:39










  • Can you post your code?
    – redberry
    Nov 10 at 20:41












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to retrieve a JSON from an external API using Volley.
Here is my code



 protected void onCreate(Bundle savedInstanceState) 
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
final TextView mTextView = findViewById(R.id.testreq);
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
@Override
public void onResponse(String response)
// Display the first 500 characters of the response string.
mTextView.setText("Response is: "+ response.substring(0,500));

, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
mTextView.setText("That didn't work");
Log.d("Error", error.toString());

);
queue.add(stringRequest);



It seems like the response is done but I am getting this error




E/Volley: [277] BasicNetwork.performRequest: Unexpected response code 500
and when I ran a test on the API in https://apitester.com/ It tells me its passed and I get this error




Response Headers
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Sat, 10 Nov 2018 19:56:18 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json
Via: 1.1 vegur



Any ideas how to solve this? Is it the API or is it me?










share|improve this question













I am trying to retrieve a JSON from an external API using Volley.
Here is my code



 protected void onCreate(Bundle savedInstanceState) 
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
final TextView mTextView = findViewById(R.id.testreq);
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
@Override
public void onResponse(String response)
// Display the first 500 characters of the response string.
mTextView.setText("Response is: "+ response.substring(0,500));

, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
mTextView.setText("That didn't work");
Log.d("Error", error.toString());

);
queue.add(stringRequest);



It seems like the response is done but I am getting this error




E/Volley: [277] BasicNetwork.performRequest: Unexpected response code 500
and when I ran a test on the API in https://apitester.com/ It tells me its passed and I get this error




Response Headers
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Sat, 10 Nov 2018 19:56:18 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json
Via: 1.1 vegur



Any ideas how to solve this? Is it the API or is it me?







java android android-studio android-volley status






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 20:01









redberry

316




316











  • @PushpeshKumarRajwanshi I do understand that status 500 means thats server error, and thats why I am asking if its me not handling the request properly or no. I wasnt going to ask if I didnt check my code already and couldnt figure it out. If theres nothing you can suggest why bother writing at all?
    – redberry
    Nov 10 at 20:22










  • I just tried accessing the URL you mentioned in your post and I am getting success response. So your problem hasn't reproduced to me. Can you try and check yourself again? May be server had some temporary problems, which got resolved. And now I can surely say, you don't have to fix anything at your end. Initially I thought may be you didn't pass some parameter or request body properly which might have resulted into this error, but that's not the case here as its a simple GET URL which needs no special headers/cookies/parameters. Sorry for the confusion and any inconvenience caused.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:28











  • That's the thing, the URL works well in browser, however when it comes to getting a response it fails with this code
    – redberry
    Nov 10 at 20:36










  • I just tried from code as well and I got the response successfully even from code. So seems like there is some silly mistake at your end only.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:39










  • Can you post your code?
    – redberry
    Nov 10 at 20:41
















  • @PushpeshKumarRajwanshi I do understand that status 500 means thats server error, and thats why I am asking if its me not handling the request properly or no. I wasnt going to ask if I didnt check my code already and couldnt figure it out. If theres nothing you can suggest why bother writing at all?
    – redberry
    Nov 10 at 20:22










  • I just tried accessing the URL you mentioned in your post and I am getting success response. So your problem hasn't reproduced to me. Can you try and check yourself again? May be server had some temporary problems, which got resolved. And now I can surely say, you don't have to fix anything at your end. Initially I thought may be you didn't pass some parameter or request body properly which might have resulted into this error, but that's not the case here as its a simple GET URL which needs no special headers/cookies/parameters. Sorry for the confusion and any inconvenience caused.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:28











  • That's the thing, the URL works well in browser, however when it comes to getting a response it fails with this code
    – redberry
    Nov 10 at 20:36










  • I just tried from code as well and I got the response successfully even from code. So seems like there is some silly mistake at your end only.
    – Pushpesh Kumar Rajwanshi
    Nov 10 at 20:39










  • Can you post your code?
    – redberry
    Nov 10 at 20:41















@PushpeshKumarRajwanshi I do understand that status 500 means thats server error, and thats why I am asking if its me not handling the request properly or no. I wasnt going to ask if I didnt check my code already and couldnt figure it out. If theres nothing you can suggest why bother writing at all?
– redberry
Nov 10 at 20:22




@PushpeshKumarRajwanshi I do understand that status 500 means thats server error, and thats why I am asking if its me not handling the request properly or no. I wasnt going to ask if I didnt check my code already and couldnt figure it out. If theres nothing you can suggest why bother writing at all?
– redberry
Nov 10 at 20:22












I just tried accessing the URL you mentioned in your post and I am getting success response. So your problem hasn't reproduced to me. Can you try and check yourself again? May be server had some temporary problems, which got resolved. And now I can surely say, you don't have to fix anything at your end. Initially I thought may be you didn't pass some parameter or request body properly which might have resulted into this error, but that's not the case here as its a simple GET URL which needs no special headers/cookies/parameters. Sorry for the confusion and any inconvenience caused.
– Pushpesh Kumar Rajwanshi
Nov 10 at 20:28





I just tried accessing the URL you mentioned in your post and I am getting success response. So your problem hasn't reproduced to me. Can you try and check yourself again? May be server had some temporary problems, which got resolved. And now I can surely say, you don't have to fix anything at your end. Initially I thought may be you didn't pass some parameter or request body properly which might have resulted into this error, but that's not the case here as its a simple GET URL which needs no special headers/cookies/parameters. Sorry for the confusion and any inconvenience caused.
– Pushpesh Kumar Rajwanshi
Nov 10 at 20:28













That's the thing, the URL works well in browser, however when it comes to getting a response it fails with this code
– redberry
Nov 10 at 20:36




That's the thing, the URL works well in browser, however when it comes to getting a response it fails with this code
– redberry
Nov 10 at 20:36












I just tried from code as well and I got the response successfully even from code. So seems like there is some silly mistake at your end only.
– Pushpesh Kumar Rajwanshi
Nov 10 at 20:39




I just tried from code as well and I got the response successfully even from code. So seems like there is some silly mistake at your end only.
– Pushpesh Kumar Rajwanshi
Nov 10 at 20:39












Can you post your code?
– redberry
Nov 10 at 20:41




Can you post your code?
– redberry
Nov 10 at 20:41












3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










HTTP Status Codes starting with 5 inform that the error is on server side. The code 500 is interpreted as Internal Server Error, to solve this you have to check what might cause it. It may be caused by a mistake in the code in that case you can open your error_log to see the error and act accordingly.



It can be caused by server features being unavailable momently like accessing the database or having many simultaneous opened connections that exceed the associated mysql resources.



Some other times, the error is not logged into the error_log file. If you use a cpanel, at the homepage, under Metrics tab open Errors and check according to the time you requested to the server. If you are not using cpanel look for a corresponding server log.



With the link passed in your question that error code should not be unless it's overwritten or hardcoded in your server side script.



See these three tests:



enter image description here



With this, I set both time and cancer parameters, and as you can see, the Error Code is 500 but within the response body, every thing is okay with status 200.



enter image description here



And with this, I still have the answer even if I just set one parameter. within the response body, there is an error not server error but customized error: there is a parameter missing. Guess what's the returned HTTP code(500)



And what if I remove all parameters?



enter image description here



Every thing is okay. The HTTP Status Code and response body.
That tells me that wether the author wants you to listen to customized request status rather than the returned HTTP Status Code. That's just my point of view.






share|improve this answer





























    up vote
    0
    down vote













    Here is my code that successfully retrieves the json response from url,



     HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet("https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer");

    HttpResponse response = httpclient.execute(httpGet);
    HttpEntity resEntity = response.getEntity();

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Streams.copy(resEntity.getContent(), byteArrayOutputStream, true);

    String data = byteArrayOutputStream.toString("UTF-8");
    System.out.println(data);


    I am using HttpClient API but can be easily done by java net package.






    share|improve this answer



























      up vote
      0
      down vote













      I found a Bug on API you are using is sending response code 500 + Response Data.
      And in volley whenever response code other then 200 to 299 is detected volley run there Error Listeners to handle it. That's why your code missed your Response data because Volley Error Listener get Call First.



      Postman Picture mark with both Points



      Frankly saying this is Nonstandard Poor Way of API Designing, which throwing status code on Responses as well.



      Too things i want to tell you :



      1. Start using Postman (If you are not using it)


      2. Jamun Volley Library


      start using helper libraries this is what i recommend you to Use which handle your most methods call and provide you better error handling with custom messages and individual status codes.



      Hope this will help you to tackle future approaches.






      share|improve this answer




















        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242912%2fhow-to-deal-with-unexpected-response-500-in-android%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote



        accepted










        HTTP Status Codes starting with 5 inform that the error is on server side. The code 500 is interpreted as Internal Server Error, to solve this you have to check what might cause it. It may be caused by a mistake in the code in that case you can open your error_log to see the error and act accordingly.



        It can be caused by server features being unavailable momently like accessing the database or having many simultaneous opened connections that exceed the associated mysql resources.



        Some other times, the error is not logged into the error_log file. If you use a cpanel, at the homepage, under Metrics tab open Errors and check according to the time you requested to the server. If you are not using cpanel look for a corresponding server log.



        With the link passed in your question that error code should not be unless it's overwritten or hardcoded in your server side script.



        See these three tests:



        enter image description here



        With this, I set both time and cancer parameters, and as you can see, the Error Code is 500 but within the response body, every thing is okay with status 200.



        enter image description here



        And with this, I still have the answer even if I just set one parameter. within the response body, there is an error not server error but customized error: there is a parameter missing. Guess what's the returned HTTP code(500)



        And what if I remove all parameters?



        enter image description here



        Every thing is okay. The HTTP Status Code and response body.
        That tells me that wether the author wants you to listen to customized request status rather than the returned HTTP Status Code. That's just my point of view.






        share|improve this answer


























          up vote
          0
          down vote



          accepted










          HTTP Status Codes starting with 5 inform that the error is on server side. The code 500 is interpreted as Internal Server Error, to solve this you have to check what might cause it. It may be caused by a mistake in the code in that case you can open your error_log to see the error and act accordingly.



          It can be caused by server features being unavailable momently like accessing the database or having many simultaneous opened connections that exceed the associated mysql resources.



          Some other times, the error is not logged into the error_log file. If you use a cpanel, at the homepage, under Metrics tab open Errors and check according to the time you requested to the server. If you are not using cpanel look for a corresponding server log.



          With the link passed in your question that error code should not be unless it's overwritten or hardcoded in your server side script.



          See these three tests:



          enter image description here



          With this, I set both time and cancer parameters, and as you can see, the Error Code is 500 but within the response body, every thing is okay with status 200.



          enter image description here



          And with this, I still have the answer even if I just set one parameter. within the response body, there is an error not server error but customized error: there is a parameter missing. Guess what's the returned HTTP code(500)



          And what if I remove all parameters?



          enter image description here



          Every thing is okay. The HTTP Status Code and response body.
          That tells me that wether the author wants you to listen to customized request status rather than the returned HTTP Status Code. That's just my point of view.






          share|improve this answer
























            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            HTTP Status Codes starting with 5 inform that the error is on server side. The code 500 is interpreted as Internal Server Error, to solve this you have to check what might cause it. It may be caused by a mistake in the code in that case you can open your error_log to see the error and act accordingly.



            It can be caused by server features being unavailable momently like accessing the database or having many simultaneous opened connections that exceed the associated mysql resources.



            Some other times, the error is not logged into the error_log file. If you use a cpanel, at the homepage, under Metrics tab open Errors and check according to the time you requested to the server. If you are not using cpanel look for a corresponding server log.



            With the link passed in your question that error code should not be unless it's overwritten or hardcoded in your server side script.



            See these three tests:



            enter image description here



            With this, I set both time and cancer parameters, and as you can see, the Error Code is 500 but within the response body, every thing is okay with status 200.



            enter image description here



            And with this, I still have the answer even if I just set one parameter. within the response body, there is an error not server error but customized error: there is a parameter missing. Guess what's the returned HTTP code(500)



            And what if I remove all parameters?



            enter image description here



            Every thing is okay. The HTTP Status Code and response body.
            That tells me that wether the author wants you to listen to customized request status rather than the returned HTTP Status Code. That's just my point of view.






            share|improve this answer














            HTTP Status Codes starting with 5 inform that the error is on server side. The code 500 is interpreted as Internal Server Error, to solve this you have to check what might cause it. It may be caused by a mistake in the code in that case you can open your error_log to see the error and act accordingly.



            It can be caused by server features being unavailable momently like accessing the database or having many simultaneous opened connections that exceed the associated mysql resources.



            Some other times, the error is not logged into the error_log file. If you use a cpanel, at the homepage, under Metrics tab open Errors and check according to the time you requested to the server. If you are not using cpanel look for a corresponding server log.



            With the link passed in your question that error code should not be unless it's overwritten or hardcoded in your server side script.



            See these three tests:



            enter image description here



            With this, I set both time and cancer parameters, and as you can see, the Error Code is 500 but within the response body, every thing is okay with status 200.



            enter image description here



            And with this, I still have the answer even if I just set one parameter. within the response body, there is an error not server error but customized error: there is a parameter missing. Guess what's the returned HTTP code(500)



            And what if I remove all parameters?



            enter image description here



            Every thing is okay. The HTTP Status Code and response body.
            That tells me that wether the author wants you to listen to customized request status rather than the returned HTTP Status Code. That's just my point of view.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 at 21:18

























            answered Nov 10 at 21:00









            gratien asimbahwe

            7601722




            7601722






















                up vote
                0
                down vote













                Here is my code that successfully retrieves the json response from url,



                 HttpClient httpclient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet("https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer");

                HttpResponse response = httpclient.execute(httpGet);
                HttpEntity resEntity = response.getEntity();

                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                Streams.copy(resEntity.getContent(), byteArrayOutputStream, true);

                String data = byteArrayOutputStream.toString("UTF-8");
                System.out.println(data);


                I am using HttpClient API but can be easily done by java net package.






                share|improve this answer
























                  up vote
                  0
                  down vote













                  Here is my code that successfully retrieves the json response from url,



                   HttpClient httpclient = new DefaultHttpClient();
                  HttpGet httpGet = new HttpGet("https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer");

                  HttpResponse response = httpclient.execute(httpGet);
                  HttpEntity resEntity = response.getEntity();

                  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                  Streams.copy(resEntity.getContent(), byteArrayOutputStream, true);

                  String data = byteArrayOutputStream.toString("UTF-8");
                  System.out.println(data);


                  I am using HttpClient API but can be easily done by java net package.






                  share|improve this answer






















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Here is my code that successfully retrieves the json response from url,



                     HttpClient httpclient = new DefaultHttpClient();
                    HttpGet httpGet = new HttpGet("https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer");

                    HttpResponse response = httpclient.execute(httpGet);
                    HttpEntity resEntity = response.getEntity();

                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    Streams.copy(resEntity.getContent(), byteArrayOutputStream, true);

                    String data = byteArrayOutputStream.toString("UTF-8");
                    System.out.println(data);


                    I am using HttpClient API but can be easily done by java net package.






                    share|improve this answer












                    Here is my code that successfully retrieves the json response from url,



                     HttpClient httpclient = new DefaultHttpClient();
                    HttpGet httpGet = new HttpGet("https://horoscope-free-api.herokuapp.com/?time=today&sign=cancer");

                    HttpResponse response = httpclient.execute(httpGet);
                    HttpEntity resEntity = response.getEntity();

                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    Streams.copy(resEntity.getContent(), byteArrayOutputStream, true);

                    String data = byteArrayOutputStream.toString("UTF-8");
                    System.out.println(data);


                    I am using HttpClient API but can be easily done by java net package.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 10 at 20:47









                    Pushpesh Kumar Rajwanshi

                    2,6721821




                    2,6721821




















                        up vote
                        0
                        down vote













                        I found a Bug on API you are using is sending response code 500 + Response Data.
                        And in volley whenever response code other then 200 to 299 is detected volley run there Error Listeners to handle it. That's why your code missed your Response data because Volley Error Listener get Call First.



                        Postman Picture mark with both Points



                        Frankly saying this is Nonstandard Poor Way of API Designing, which throwing status code on Responses as well.



                        Too things i want to tell you :



                        1. Start using Postman (If you are not using it)


                        2. Jamun Volley Library


                        start using helper libraries this is what i recommend you to Use which handle your most methods call and provide you better error handling with custom messages and individual status codes.



                        Hope this will help you to tackle future approaches.






                        share|improve this answer
























                          up vote
                          0
                          down vote













                          I found a Bug on API you are using is sending response code 500 + Response Data.
                          And in volley whenever response code other then 200 to 299 is detected volley run there Error Listeners to handle it. That's why your code missed your Response data because Volley Error Listener get Call First.



                          Postman Picture mark with both Points



                          Frankly saying this is Nonstandard Poor Way of API Designing, which throwing status code on Responses as well.



                          Too things i want to tell you :



                          1. Start using Postman (If you are not using it)


                          2. Jamun Volley Library


                          start using helper libraries this is what i recommend you to Use which handle your most methods call and provide you better error handling with custom messages and individual status codes.



                          Hope this will help you to tackle future approaches.






                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            I found a Bug on API you are using is sending response code 500 + Response Data.
                            And in volley whenever response code other then 200 to 299 is detected volley run there Error Listeners to handle it. That's why your code missed your Response data because Volley Error Listener get Call First.



                            Postman Picture mark with both Points



                            Frankly saying this is Nonstandard Poor Way of API Designing, which throwing status code on Responses as well.



                            Too things i want to tell you :



                            1. Start using Postman (If you are not using it)


                            2. Jamun Volley Library


                            start using helper libraries this is what i recommend you to Use which handle your most methods call and provide you better error handling with custom messages and individual status codes.



                            Hope this will help you to tackle future approaches.






                            share|improve this answer












                            I found a Bug on API you are using is sending response code 500 + Response Data.
                            And in volley whenever response code other then 200 to 299 is detected volley run there Error Listeners to handle it. That's why your code missed your Response data because Volley Error Listener get Call First.



                            Postman Picture mark with both Points



                            Frankly saying this is Nonstandard Poor Way of API Designing, which throwing status code on Responses as well.



                            Too things i want to tell you :



                            1. Start using Postman (If you are not using it)


                            2. Jamun Volley Library


                            start using helper libraries this is what i recommend you to Use which handle your most methods call and provide you better error handling with custom messages and individual status codes.



                            Hope this will help you to tackle future approaches.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 13 at 18:04









                            Jatin Sahgal

                            11




                            11



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242912%2fhow-to-deal-with-unexpected-response-500-in-android%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                這個網誌中的熱門文章

                                What does pagestruct do in Eviews?

                                Dutch intervention in Lombok and Karangasem

                                Channel Islands