Get PATCH request data in PHP

前端 未结 4 1497
無奈伤痛
無奈伤痛 2020-12-16 12:08

I need to make a PATCH request to a PHP application.

How can I get the data from that PATCH request inside that application?

If I h

4条回答
  •  难免孤独
    2020-12-16 12:49

    Since none of the above has worked for me in PHP 5.6, here's a solution that actually did.

    I used this parse_raw_http_request($data) function by Christof.

    And here's the code:

    $_PATCH = [];
    parse_str(file_get_contents('php://input'), $_PATCH);
    parse_raw_http_request($_PATCH);
    
    // From now on, the $_PATCH variable keeps all request arguments as well,
    // and they're accessible under approprate keys like $_PATCH['yourKey']
    

提交回复
热议问题