java http 500错误怎么解决_java – Android中的Http 500内部服务器错误

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值