java - Android 中的 Http 500 内部服务器错误

标签 java android

安卓代码

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

网络服务

这是我从浏览器调用的网络服务,它工作正常。但是,当我从 Android 调用时,我收到了 500 内部服务器错误。但是在服务器日志中我没有看到任何错误。

出了什么问题?

最佳答案

每当 HTTP code以 5 (5xx) 开头,表示服务器出现问题。这不是关于你的代码,在 android 客户端,而是在服务器端实现。

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

这可能意味着您从 Android 应用程序发送的请求负载必须与您从浏览器发送的请求负载不同。请打印您的请求负载并仔细检查所有内容。此外,它还可以帮助您查看请求 header 。

关于java - Android 中的 Http 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19975282/

相关文章:

java - 通用可变参数的警告

android - 使用接口(interface)将数据从 Activity 传递到 Fragment

android - java.lang.NoClassDefFoundError : android/test/AndroidTestCase 错误

java - 如何从另一个 fragment 更新 DialogFragment 的 Textview

android - Android 上电子邮件中的 HTML 链接

java - 为什么\n 和 (String)System.getProperty ("line.separator");采取不同的行动?

java - 使用 jasperreport 生成的 PDF 在 Linux 上显示效果不佳,但在 Mac 上显示效果良好,可能与操作系统有关吗?

java - 如何将 String 解析为具有默认值的 int?

java - 解释 JDBC 连接

java - Android 与像素的关系。我的 2D 瓷砖 map 遇到了严重的问题?