Ads Inside Post

Search in This Blog

Post data using curl

Problem:

How to post data using curl in php?

Solution:

You need to use  POST method in curl.

Example:

$str_to_post = "login=mylogin&pass=mypass";
$crl = curl_init('http://localhost/mysite/dologin');
curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($crl, CURLOPT_POSTFIELDS,$str_to_post );
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
$ans = curl_exec($crl);

Other example is:

$postdata = array(
    'login' => 'mylogin',
    'pass' => 'mypass',
    'logintype' => '1'
);
$crl = curl_init();
curl_setopt($crl, CURLOPT_URL, "http://localhost/mysite/dologin");
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, true);
curl_setopt($crl, CURLOPT_POSTFIELDS, $postdata);
$ans = curl_exec($crl);