![](/img/trans.png)
[英]text/html format in codeigniter rest_controller response
[英]Codeigniter rest controller post response as xml format
当我尝试使用format(json / xml / HTML)进行调用时,我正在使用Codeigniter REST_Controller进行API调用,并且其工作正常
但是,当我尝试进行post调用时,这里需要XML数据,但始终无法获取XML数据。 它总是只显示JSON数据。 这里是分享我的问题的屏幕截图
我的控制器是
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH.'libraries/REST_Controller.php');
class User extends REST_Controller {
public function index_post()
{
$this->response($this->post());
}
}
REST_Controller使用服务器变量CONTENT_TYPE通过库中的以下方法检测格式类型:
protected function _detect_input_format()
{
// Get the CONTENT-TYPE value from the SERVER variable
$content_type = $this->input->server('CONTENT_TYPE');
if (empty($content_type) === FALSE)
{
// If a semi-colon exists in the string, then explode by ; and get the value of where
// the current array pointer resides. This will generally be the first element of the array
$content_type = (strpos($content_type, ';') !== FALSE ? current(explode(';', $content_type)) : $content_type);
// Check all formats against the CONTENT-TYPE header
foreach ($this->_supported_formats as $type => $mime)
{
// $type = format e.g. csv
// $mime = mime type e.g. application/csv
// If both the mime types match, then return the format
if ($content_type === $mime)
{
return $type;
}
}
}
您可以编写自己的方法,以防POST请求和使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.