gpt4 book ai didi

json - 如何使用Code Igniter REST_Controller定义内容类型

转载 作者:行者123 更新时间:2023-12-03 13:48:53 26 4
gpt4 key购买 nike

我正在使用REST_Controller扩展CI_Controller,由于某种原因,我的请求都以text/html而不是json的内容类型返回。在我的配置中,我将json设置为默认格式:

$config['rest_default_format'] = 'json';

我的结果以JSON的形式返回,但未设置内容类型。有人可以帮我解决我所缺少的吗?

最佳答案

我不确定配置是否设置了格式。但是一个简单的解决方法可能只是使用输出类来设置 header 内容类型,例如:

$this->output
->set_content_type('application/json')
->set_output(json_encode(array('foo' => 'bar')));

(摘自手册: here)

关于json - 如何使用Code Igniter REST_Controller定义内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10841102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com