php - apache 的 CORS 问题

标签 php angular apache .htaccess centos

我在向我的 API 服务器发出请求时遇到问题。 (它以前工作过),我不确定发生了什么变化,事情似乎有意义,但我一定错过了一些东西。

我尝试查看各种文章和问题,例如 CORS Issue - Angular / PHP / Apache
https://dev.to/effingkay/cors-preflighted-requests--options-method-3024
https://awesometoast.com/cors/

  post(platforms, message: string): any {
    console.log("Posting...");
    const data = {
      platforms,
      message
    };

    return this.http.post(`${this.baseUrl}/post`, data);
  }

这是应该运行的 php 方法:
    public function post()
    {
        return response(200);

    }

我只想看到 200 响应返回。但是我会收到以下错误:
    Access to XMLHttpRequest at 'http://my.domain/api/customer-dash/post' from origin 'http://my.domain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

.htaccess
#always set these headers.
Header always set Access-Control-Allow-Origin "http://my.domain"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"

# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

技术栈是 centos 7 服务器上的 angular、php 和 apache

谢谢

最佳答案

我的 services.php 文件中存在语法错误 - 问题已解决

关于php - apache 的 CORS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57164313/

相关文章:

php - php 中的 a+(读取/追加)与 a(追加)有何不同

javascript - 在 angular6 模板中使用 getter 方法或类变量?

angular - 如何检测 angular2 中的引导日期时间选择器更改事件

apache - 如何使用 Apache 重写规则从 URL 中删除多个正斜杠?

php - Yii2 htaccess - 如何完全隐藏前端/web 和后端/web

php - 如何解决 Laravel - 无法找到驱动程序错误?

php - 遍历数组(+100 个值)

javascript - Angular 2将html属性从父级传递给子级

windows - RewriteRule 根本不在 .htaccess for Windows (Apache) 中写入

php - PDO 使用 where 子句选择多个表