AMP形式amp_source_origin错误cors标头

时间:2017-06-29 13:48:07

标签: forms cors amp-html

我在AMP表格中收到错误

 <form class="innler-left" method="post" action-xhr="//mydoma.com/ xxxx/xxx/xxx/send.php" target="_top">

在控制台中提交以下错误。

Response must contain the AMP-Access-Control-Allow-Source-Origin header
Form submission failed: Error: 
Response must contain the AMP-Access-Control-Allow-Source-Origin header​​​ _reported_

一旦用户提交表单,它就会将php文件放在我放置以下标题的位置

header('HTTP/1.1 200 OK');
header("access-control-allow-credentials:true");
header("AMP-Same-Origin: true");
header("Access-Control-Allow-Origin:".$_SERVER['HTTP_ORIGIN']);
header("amp-access-control-allow-source-origin: https://".$_SERVER['HTTP_HOST']);
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header("access-control-allow-headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
header("access-control-allow-methods:POST, GET, OPTIONS");
header("Content-Type: application/json");

我让它在本地计算机上脱机工作但是一旦我上传文件,它就无法正常工作:(

尝试https://github.com/ampproject/amphtml/blob/master/spec/amp-cors-requests.md

POST __amp_source_origin不匹配!

1 个答案:

答案 0 :(得分:0)

我也遇到了同样的问题需要解决此问题,请确保您的网址以https开头。并尝试在代码中替换以下行:

header("Access-Control-Allow-Origin:".$_SERVER['HTTP_ORIGIN']);

header("Access-Control-Allow-Origin: ". str_replace('.', '-','https://www.example.com') .".cdn.ampproject.org");

注意: https://www.example.com替换为您的AMP网站网址

希望它有所帮助。