AMP Access Control Allow Source Origin header Issue(AMP 访问控制允许 Source Origin 标头问题)
问题描述
如何解决以下错误;
<块引用>加载资源失败:服务器响应状态为 500(内部服务器错误)cdn.ampproject.org/v0.js:68 响应必须包含 AMP-Access-Control-Allow-Source-Origin 标头码@cdn.ampproject.org/v0.js:68cdn.ampproject.org/v0.js:68 表单提交失败:错误:响应必须包含 AMP-Access-Control-Allow-Source-Origin 标头 reported
遵循
请尝试以下代码
if(!empty($_POST)){$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") ."://$_SERVER[HTTP_HOST]";header("内容类型:应用程序/json");header("Access-Control-Allow-Credentials: true");header("Access-Control-Allow-Origin: ".str_replace('.', '-','https://example.com') .".cdn.ampproject.org");header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");header("AMP-Redirect-To: https://example.com/thankyou.amp.html");header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");echo json_encode(array('successmsg'=>'data post'));出口;}
<块引用>
请确保域 url 应该是 https
将 https://example.com/ 替换为您想要的网址
How can I resolve the error below;
Failed to load resource: the server responded with a status of 500 (Internal Server Error) cdn.ampproject.org/v0.js:68 Response must contain the AMP-Access-Control-Allow-Source-Origin header Yd @ cdn.ampproject.org/v0.js:68 cdn.ampproject.org/v0.js:68 Form submission failed: Error: Response must contain the AMP-Access-Control-Allow-Source-Origin header reported
Followed all instructions at the AMP GitHub Page on CORS.
Below is a screenshot of my PHP code at the server side and error in the console of my browser;
Please try with following code
if(!empty($_POST)){
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
header("Content-type: application/json");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: ". str_replace('.', '-','https://example.com') .".cdn.ampproject.org");
header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header("AMP-Redirect-To: https://example.com/thankyou.amp.html");
header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");
echo json_encode(array('successmsg'=>'data post'));
exit;
}
Please make sure that domain url should be https
Replace https://example.com/ to your desired url
这篇关于AMP 访问控制允许 Source Origin 标头问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AMP 访问控制允许 Source Origin 标头问题
基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01