解決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...跨域

相關文章
相關標籤/搜索