class BirthdayTask extends AsyncTask{
@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 userProfiles = userProfileManager.getUpcomingBirthday(domain.getDomainId(),15);
return gson.toJson(userProfiles);
}
网络服务
这是我从浏览器调用的web服务工作正常.但是当我从Android调用时,我得到500内部服务器错误.但在服务器日志中,我看到没有错误.
出了什么问题?
解决方法:
很难给出答案,但我认为当您使用Android调用WS时会话为空.虽然如果你使用浏览器调用WS,会话可以使用cookie或sessionId进行保存,但是我找不到以某种方式处理cookie或sessionId的任何代码行.
IMO你不应该依赖会话信息.
希望它能帮到你.
标签:java,android
来源: https://codeday.me/bug/20190612/1227194.html