解决axios 跨域问题 - 服务端修改

登陆请求html

login (data)java

return axios({
  method: 'post',
  url: userApi.loginUrl(),
  data: data,
  withCredentials: true
}) }

向服务端发送请求出现
图片描述ios

在服务端pom.xml中添加
<!-- 跨域请求依赖 -->web

<dependency>
        <groupId>com.thetransactioncompany</groupId>
        <artifactId>cors-filter</artifactId>
        <version>2.5</version>
    </dependency>

在服务端web.xml中添加
<!-- cors filter -->axios

<filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

    <init-param>
        <param-name>cors.allowOrigin</param-name>
        <param-value>*</param-value>
    </init-param>
    <async-supported>true</async-supported>
</filter>
<filter-mapping>
    <filter-name>CORS</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

跨域参考文档:http://www.boyunjian.com/java...跨域

相关文章
相关标签/搜索