CodeIgniter restserver problem Solving for put request not getting parameters _php tutorial

Source: Internet
Author: User
Tags codeigniter

Problem solving for put request not getting parameters in CodeIgniter restserver


Recently encountered an egg ache problem with restserver, found that $this->put get parameters are null. Check it out. This seems to be a common problem, see Links: https://github.com/chriskacerguis/codeigniter-restserver/issues/362

Let's take a look at the official explanation: see http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter-2--net-8814

$this->put () Reads in put arguments set in the HTTP headers or via CURL.

That is, the function can read the put parameter that is carried when accessed through curl, or the parameter in the HTTP headers. But after testing, even if the parameter is put in headers, $this->put () can not access, the root cause may be in the source of a place to shield. Zajia has not found a solution to the basic method, but the following two can temporarily solve the problem:

1, consistent with post, still pass parameters in body. Write a function in the base class:

    Public Function Getput ($key) {        return $this->input->input_stream ($key);    }
When the client accesses the normal parameters in the body, it is OK. Note that this time through $this->post () is not obtained parameters, must be taken from the Input_stream. The above function supports simultaneous fetching of multiple fields, such as:
$data = $this->getput (The Array (' Tel ', ' name ', ' addr '));
In fact, the function from input in CI should support multiple fields simultaneously, but Restserver's This->get () post () is not supported.

Add: When the parameters are placed in the body, directly with $this->put () can be obtained to the corresponding field, the document is said to be in the headers, is actually in the body! However, $this->put () does not support multiple fields, so the above function is meaningful.

$this->delete () also have this problem, can not read the parameters in the headers, but to read the body of!!!

2, the parameter is passed in the header, the base class writes a function:

    /**     * Get header corresponding to key     * @param $key     * @return Mixed     *    /Public Function GetHeader ($key) {        return $this->input->get_request_header ($key, TRUE);    }

Personal recommendation the first kind of Kazakhstan, the parameters in the body pass! The best way to follow the HTTP rules, don't suck in the header.

The problem with the Ps:restserver put parameter is not related to the Content-type:application/json setting.

http://www.bkjia.com/PHPjc/1088531.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088531.html techarticle CodeIgniter Restserver A put request does not get parameters to solve the problem of the recent use of restserver encountered an egg pain, found that the $this-put get the parameters are null. Check the discovery, this appearance ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.