简体   繁体   中英

Codeigniter rest controller post response as xml format

I am using Codeigniter REST_Controller for making API calls, when I tried to get call with format( json / xml / HTML ), and its working

but when I tried to make the post call, here I need XML data as a result but it always failed to get XML data. It's always showing JSON data only. Here am sharing a screenshot of my problem

在此处输入图片说明

My Controller is

<?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_Controlleris using server variable CONTENT_TYPE to detect format type using below method in library:

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;
                }
            }
        }

You can write your own method in case of POST Request and use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM