cUrl 簡單使用

curl.php


<?php 
//目標URL
$url = 'http://localhost/test/curl/post.php';

$post_data = array(
    'name'=>'Resory',
    'company'=>'Cxx Txx',
    'position'=>'PHP programmer',       
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

//設置請求為POST類型
curl_setopt($ch, CURLOPT_POST, 1);
//添加post數據到請求中
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);

//執行post請求,獲得回覆.
$response = curl_exec($ch);

curl_close($ch);

echo $response;

?>

post.php


<?php 
$_POST['prove'] = 'you have been post.php !';
print_r($_POST);
?>

output(curl.php):

Array
(

[name] => Resory
[company] => Cxx Txx
[position] => PHP programmer
[prove] => you have been post.php !

)

more detail :http://www.360weboy.com/web-service/curl.html

你可能感兴趣的:(PHP,curl)