Php Codeigniter rest控制器以xml格式发布响应
我使用Codeigniter REST_控制器进行API调用, 当我尝试使用格式(json/xml/HTML)获取调用时,它可以正常工作 但是当我尝试进行post调用时,这里我需要XML数据,但它总是无法获取XML数据。它总是只显示JSON数据。这里我分享我的问题截图 我的控制器是Php Codeigniter rest控制器以xml格式发布响应,php,json,xml,codeigniter,Php,Json,Xml,Codeigniter,我使用Codeigniter REST_控制器进行API调用, 当我尝试使用格式(json/xml/HTML)获取调用时,它可以正常工作 但是当我尝试进行post调用时,这里我需要XML数据,但它总是无法获取XML数据。它总是只显示JSON数据。这里我分享我的问题截图 我的控制器是 <?php defined('BASEPATH') OR exit('No direct script access allowed'); require(APPPATH.'libraries/REST_Co
<?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\u控制器使用服务器变量内容类型在库中使用以下方法检测格式类型:
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请求的情况下,您可以编写自己的方法并使用。REST\u控制器使用服务器变量内容类型在库中使用以下方法检测格式类型:
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请求的情况下,您可以编写自己的方法并使用。您必须在显示htmlCheck的屏幕截图中传递format=xml。您的URL应该看起来像http://localhost/resume/user?format=xml
。是啊!我也试过了,它不起作用我需要一个POST请求的解决方案,我可以像这样发送数据吗“”,即使它不起作用,你必须在显示htmlCheck的屏幕截图中传递format=xml。您的URL应该看起来像http://localhost/resume/user?format=xml
。是啊!我也试过了,它不起作用我需要一个POST请求的解决方案,我可以像这样发送数据吗?即使它不起作用