gpt4 book ai didi

php - apache 的 CORS 问题

转载 作者:行者123 更新时间:2023-12-04 19:31:56 25 4
gpt4 key购买 nike

我在向我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com