我正在使用
spring mvc实现REST API端点.我试图发回一个带有cookie值的HTTP响应.
这相当于我在
ruby SINATRA中需要做的事情:
response.set_cookie('heroku-nav-data', :value => params['nav-data'], :path => '/')
这是我到目前为止所尝试的,但是没有用:
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity single_sign_on(@RequestBody String body_sso) {
String[] tokens = body_sso.split("&");
String nav_data=tokens[3].substring(9);
String id = tokens[2].substring(3);
String time_param = tokens[0].substring(10);
long timestamp= Long.valueOf(time_param).longValue();
String pre_token = id+':'+HEROKU_SSO_SALT+':'+time_param;
String token = DigestUtils.shaHex(pre_token);
long lDateTime = new Date().getTime()/1000;
if (!((token.equals(tokens[4].substring(6))) && ((lDateTime-timestamp)<300)))
{
return new ResponseEntity(HttpStatus.FORBIDDEN);
}
HttpHeaders headers = new HttpHeaders();
headers.add("heroku-nav-data",nav_data);// this didn't work
return new ResponseEntity(id,headers,HttpStatus.OK);
}
我该怎么办 ?谢谢.