我正在尝试使用AMP的形式来获取回复。
因为AMP页面的域位于... cdn.ampproject.org。 因此存在CORS问题。
我已引用the documents
我的放大器html代码
<form method="get" action="https://..../test">
<button type="submit">test get</button>
</form>
<form method="post" action-xhr="https://..../test">
<button type="submit">test post</button>
</form>
我的php函数
public function test()
{
header('X-Robots-Tag: noindex');
header('Content-Type: application/json');
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: " . GOOGLE_AMP_PAGE_DOMAIN);
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header("AMP-Access-Control-Allow-Source-Origin: https://" . MY_HOST);
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
echo 'success'
exit;
}
在使用method =“ get” 时有效,但在method =“ post”
时失败我得到错误控制台:
访问CORS策略已阻止从源“ https:// ........”以“ https:// ......”获取的访问:否“ Access-Control-Allow-来源的标头出现在请求的资源上。如果不透明的响应满足您的需求,请将请求的模式设置为“ no-cors”以在禁用CORS的情况下获取资源。
我不知道该怎么解决。