2

file_get_contents method can do a GET or POST request. I am wondering if it is possible to do a DELETE request with this method. I tried like below but it doesn't seem to do a DELETE Request. I am also not getting any error or exception. Is this possible?

$postdata = http_build_query($param);
$opts = array('http' =>
        array(
            'method'  => 'DELETE',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );
$context  = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1346107
  • 157
  • 4
  • 11
  • You might need to use curl - I don't think it makes sense to use `file_get_contents` for HTTP requests that *don't return a body*. – Thom Wiggers Oct 03 '13 at 12:22
  • What if my hosting doesn't provide curl? I want to know if this is possible with php without adding any extensions – user1346107 Oct 03 '13 at 12:24

1 Answers1

3

$result = file_get_contents( 'http://example.com/submit.php', false, stream_context_create(array( 'http' => array( 'method' => 'DELETE' ) )) );