最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - AxiosError: Network Error work in some device and not in others - Stack Overflow

programmeradmin10浏览0评论

I'm working on a project using ReactJS as the frontend, deployment on AWS Amplify, and Spring Boot as the backend deployed on an AWS instance. Some users are getting this error when they try to register:

NetworkError:axios Error

Yet for other users it works fine.

here is my code:

registration.js

static BASE_URL = ";;
static async register(userData) {
    console.log(JSON.stringify(userData));
    try {
        const response = await axios.post(
            `${UserService.BASE_URL}/auth/register`,
            userData,
            {
                headers: {
                    Accept: "application/json",
                    "Content-Type": "application/json",
                },
            }
        );
        console.log(response.data);
        return response.data;
    } catch (err) {
        throw err;
    }
}

my spring boot backend:

@Bean
CorsConfigurationSource corsConfigurationSource(){
    CorsConfiguration configuration=new CorsConfiguration();
    configuration.setAllowedOrigins(List.of(";));
    configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT",       "DELETE","HEAD","OPTIONS"));

    configuration.setAllowedHeaders(Arrays.asList(HttpHeaders.AUTHORIZATION
            ,HttpHeaders.CONTENT_TYPE
            ,HttpHeaders.ACCEPT));
    configuration.setAllowCredentials(true); // Allow credentials
    configuration.setMaxAge(3600L); // Optional: Set max age for preflight requests
    configuration.addAllowedHeader("*");
    UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**",configuration);
    return source;
}   
发布评论

评论列表(0)

  1. 暂无评论