Access-Control-Allow-Origin is not showing up in response headers from codeigniter(Access-Control-Allow-Origin 未显示在 codeigniter 的响应标头中)
问题描述
我的 Codeigniter 文件显示
My Codeigniter file says
$CI->output->set_header("Access-Control-Allow-Origin: *");
$CI->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
$CI->output->set_status_header(200);
$CI->output->set_content_type('application/json');
echo json_encode(array("city" => "dhaka"));
但我得到的 http 响应是:
but the http response that i get are:
Request URL:http://localhost/index.php/location/city
Request Method:POST
Status Code:200 OK
Connection:Keep-Alive
Content-Length:16
Content-Type:text/html
Date:Sun, 22 Jul 2012 10:27:32 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6
X-Powered-By:PHP/5.3.6
即使包含 Access-Control-Expose-Headers: Access-Control-Allow-Origin
,响应中仍缺少标头 Access-Control-Allow-Origin
.我有关此标头的信息来源来自 Mozilla 开发者网站
The header Access-Control-Allow-Origin
is missing in the response even after including Access-Control-Expose-Headers: Access-Control-Allow-Origin
. My source of information about this header is from Mozilla Developer Website
推荐答案
事实证明,只有当我通过 PHP 语法 header()
而不是 codeigniter 语法设置标头时,它才对我有用$CI->output->set_header()
.太可惜了.
It turns out, it worked for me only when i set the headers via the PHP syntax header()
instead of the codeigniter syntax $CI->output->set_header()
. That's sad.
感谢 @Yan 在本主题的问题中的第一条评论
Thanks to the first comment by @Yan at the Question of this topic
这篇关于Access-Control-Allow-Origin 未显示在 codeigniter 的响应标头中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Access-Control-Allow-Origin 未显示在 codeigniter 的响应标头中


基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在多维数组中查找最大值 2021-01-01