【问题标题】:AMP form amp_source_origin error cors headerAMP 表单 amp_source_origin 错误 cors 标头
【发布时间】: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://”?

标签: forms cors amp-html


【解决方案1】:

我也遇到了同样的问题来解决这个问题,请确保您的 URL 以 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 网站网址

希望对你有帮助。

【讨论】:

  • @YvetteColomb !对不起,我没有明白你的意思。您是否要求对其他帖子进行amp-html 标记编辑?
  • 好的@YvetteColomb!谢谢 :) 我会处理的
猜你喜欢
  • 1970-01-01
  • 2015-05-02
  • 1970-01-01
  • 1970-01-01
  • 2019-05-30
  • 1970-01-01
  • 2018-05-18
  • 2017-03-07
  • 2020-04-10
相关资源
最近更新 更多