转载自:https://www.jianshu.com/p/3b7cd2af48a4
源码:
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
Object accessToken = request.getHeader("token");
if(accessToken == null) {
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(401);
try {
ctx.getResponse().getWriter().write("token is empty");
}catch (Exception e){
e.printStackTrace();
}
return null;
}
return null;
}
如果输出中文,前端会显示乱码
ctx.getResponse().getWriter().write("你好");
需要在前边加上这行代码:
ctx.getResponse().setContentType("text/html;charset=UTF-8");