Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a post request without curl?

Tags:

http

php

Considering I don't want to use curl, which is a valid alternative to make a post request? Maybe Zend_http_client?

I just need the basic stuff (I need to request an url with only one post param)

like image 846
dynamic Avatar asked Dec 21 '11 21:12

dynamic


1 Answers

you can use stream_context_create and file_get_contents

<?php
$context_options = array (
        'http' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
                . "Content-Length: " . strlen($data) . "\r\n",
            'content' => $data
            )
        );
?>


$context = stream_context_create($context_options); 
$result = file_get_contents('http://www.php.net', false, $context);
like image 60
Saurabh Chandra Patel Avatar answered Oct 21 '22 08:10

Saurabh Chandra Patel