【发布时间】:2017-11-17 05:50:51
【问题描述】:
我在 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 不匹配!
【问题讨论】:
-
你能调试一下 .$_SERVER['HTTP_HOST'] 产生的东西吗?是否需要在前面加上:“https://”?