Handling PUT/DELETE arguments in PHP

前端 未结 6 1265
盖世英雄少女心
盖世英雄少女心 2020-11-30 21:30

I am working on my REST client library for CodeIgniter and I am struggling to work out how to send PUT and DELETE arguments in PHP.

In a few places I have seen peopl

6条回答
  •  没有蜡笔的小新
    2020-11-30 22:14

    Just remember, most webservers do not handle PUT & DELETE requests. Since you're making a library, I'd suggest thinking about accounting for this. Typically, there are two conventions you can use to mimic PUT & DELETE via POST.

    1. use a custom POST variable (ex. _METHOD=PUT) which overrides POST
    2. set a custom HTTP header (ex. X-HTTP-Method-Override: PUT)

    Generally speaking, most RESTful services that don't allow PUT & DELETE directly will support at least one of those strategies. You can use cURL to set a custom header if you need via the CURLOPT_HTTPHEADER option.

    // ex...
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT') );
    

提交回复
热议问题