For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Wednesday, January 07, 2015

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);
Share:

0 comments:

Post a Comment

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip