获取登录接口json数据

提问 未结 5 134
wndayday
wndayday VIP3 2019-01-11 10:18:04
悬赏:20积分 收藏
产品:ani 版本:2.41
请问登陆的接口应该怎么调用呀 http://localhost:8080/jeeplus/a/login?username=admin&password=admin&mobileLogin=true 这个总是返回一个html页面 不是json数据
回帖
  • 2019-01-11 11:16:44
    请用post请求。
    0 回复
  • 2019-01-11 11:42:19
    @蓝色忧郁 用post时,我服务端设置了跨域的filter,但是始终报错 Failed to load http://127.0.0.1:8080/huangzangsi/a/login?__ajax: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8848' is therefore not allowed access 用get就没这个错误,请问怎么结局
    0 回复
  • 2019-01-11 11:46:45
    @蓝色忧郁 这是filter代码 package com.jeeplus.filter; import java.io .IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class CORSFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; HttpServletRequest request = (HttpServletRequest)servletRequest; //String origin = request.getHeader("Origin"); response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization"); response.setHeader("Access-Control-Allow-Credentials", "true"); String method = request.getMethod(); if(method.equalsIgnoreCase("OPTIONS")){ servletResponse.getOutputStream().write("Success".getBytes("utf-8")); }else{ filterChain.doFilter(servletRequest, servletResponse); } } @Override public void destroy() { } }
    0 回复
  • 2019-01-11 11:58:40
    controller 上加注解。@CrossOrigin
    0 回复
  • 2019-01-11 12:14:06
    @蓝色忧郁 现在可以post了 但是用post依然返回的是html
    0 回复