Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http 500 Internal Server Error in Android

Tags:

java

android

Android code

class BirthdayTask extends AsyncTask<String, String, String>{

        @Override
        protected String doInBackground(String... uri) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response;
            String responseString = null;
            try {
                System.out.println(uri[0]);
                response = httpclient.execute(new HttpGet(uri[0]));
                StatusLine statusLine = response.getStatusLine();
                if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    response.getEntity().writeTo(out);
                    out.close();
                    responseString = out.toString();
                    System.out.println("responseString"+responseString);
                } else{
                    //Closes the connection.
                    response.getEntity().getContent().close();
                    throw new IOException(statusLine.getReasonPhrase());
                }
            } catch (ClientProtocolException e) {
                //TODO Handle problems..
            } catch (Exception e) {
                e.printStackTrace();
            }
            return responseString;
        }


        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            /* System.out.println(result);
            System.out.println(result);
            System.out.println(result);*/
        }

    }


 @RequestMapping(value="here is my url" ,method=RequestMethod.GET)
        public @ResponseBody String Test(HttpServletRequest req) {

            Gson gson = new Gson();

            Domain domain = (Domain)req.getSession().getAttribute("Domain");
            List<UserProfile> userProfiles = userProfileManager.getUpcomingBirthday(domain.getDomainId(),15);

            return gson.toJson(userProfiles);
        }

Webservice

This is the webservice I am calling from browser its working fine. But when I call from Android then I get a 500 internal server error. But in server logs I see no error.

What is going wrong?


2 Answers

Whenever an HTTP code starts with a 5 (5xx), it means something got wrong on the server. It is not about your code here, on the android client side, but in the server side implementation.

This is webservice I am calling from broweser its woriking fine ....But when I am calling from android then 500 internal server error

This may mean the the request payload that you are sending from your android app, must be different to that when you do it from your browser. Please print your request payload and double-check everything. Additionally, it might help you also give the request headers a look.

like image 161
Abdul Wasae Avatar answered May 09 '26 14:05

Abdul Wasae


It is hard to give an answer, but i think the session is null when you call the WS using Android. While if you call the WS using a browser the session could be mantained using cookie or sessionId i dont find any line of code that handles cookies or sessionId in some way. IMO you shouldnt rely on session information. Hope it helps you.

like image 37
FrancescoAzzola Avatar answered May 09 '26 15:05

FrancescoAzzola



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!