首页 > 解决方案 > Angular 6:Http 失败响应(Microsoft Edge)

问题描述

我正在尝试调用 API,但是在使用 M Edge 时遇到了问题(Chrome、IE 和 Firefox 都可以)。对于我尝试执行的每个请求,我都会在控制台中收到以下错误:

在此处输入图像描述

这是我的服务:

@Injectable({ providedIn: 'root' })
export class AuthService {
    constructor(private http: HttpClient) {}

    signup(
        firstName: string,
        lastName: string,
        email: string,
        country: string,
        password: string
    ) {
        const data = {
            firstName: firstName,
            lastName: lastName
        };

        const headers = new HttpHeaders({
            'Content-Type': 'application/json; charset=utf-8'
        });

        return this.http.post('https://api.lan/new/', data, {
            headers: headers,
            observe: 'response'
        });
    }
} 

API Nginx 配置:

server {
    listen 80;
    listen [::]:80;

    server_name     visionapi-dev.arkadin.lan;

    root            /var/www/online-vision-api/httpdocs;
    error_log   /var/www/online-vision-api/logs/error_log;
    access_log      /var/www/online-vision-api/logs/access_log;
    index           index.php;

    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow_Credentials' 'true' always;
    add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;

    location / {
            if ($request_method = 'OPTIONS') {
                    add_header 'Access-Control-Allow-Origin' '*' always;
                    add_header 'Access-Control-Allow_Credentials' 'true' always;
                    add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
                    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
                    add_header 'Access-Control-Max-Age' 1728000 always;
                    add_header 'Content-Length' 0 always;
                    return 204;
            }
            # Check if a file or directory index file exists, else route it to index.php.
            try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;

            fastcgi_pass                    unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_read_timeout    180;
    }
}

我已经疯狂地谷歌了,有人知道吗?

谢谢!

标签: angularmicrosoft-edge

解决方案


推荐阅读