本文介绍了在Android的HTTP 500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的code

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);
        }

web服务

这是web服务我从broweser其woriking精细调用....但是,当我从安卓然后调用500内部服务器错误....但在服务器日志中没有错误,请.....找到这个解决方案。提前致谢。

This is webservice I am calling from broweser its woriking fine ....But when I am calling from android then 500 internal server error....but in server logs no error .....Please find solution for this. Thanks in advance.

推荐答案

这是很难给出一个答案,但我认为,当你调用使用的是Android的WS会话为空。而如果你使用的浏览器会话可以用Cookie或进行的sessionId调用编程和维持的WS我不觉得code处理cookie或的sessionId以某种方式中的任何行。
IMO你不应该依赖于会话信息。
希望它可以帮助你。

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.

这篇关于在Android的HTTP 500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:48