欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

cUrl 簡單使用

程序员文章站 2022-05-24 14:38:42
...

curl.php

<!-- lang: 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

<!-- lang: 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

转载于:https://my.oschina.net/resory/blog/102294