安卓代码
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/