PHP accessing Incoming PUT Data

2019-02-19 23:10发布

问题:

Is PUT similar to POST?

I'm getting some inbound requests (apache) with this: [REQUEST_METHOD] => PUT

I've never worked with this request method before. So I have to ask if I'm supposed to process it differently.

The people sending me data are claiming to be sending xml. So my script has this:

<?php
if(isset($HTTP_RAW_POST_DATA)) {
    mail("me@myemail.com","some title i want", print_r($HTTP_RAW_POST_DATA, true)); 
}else{
    die("not post data");
}
?>

I'm stuck here now. If there's a PUT request, do I replace $HTTP_RAW_POST_DATA with something else?

回答1:

According to the php docs, PUT data can be read using the php://input stream (which is preferred over $HTTP_RAW_POST_DATA).

$putdata = fopen("php://input", "r");
$str = stream_get_contents($putdata);
fclose($putdata);


标签: php put