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

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive