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
上一篇: Spring中@Qualifier注解
下一篇: Spring @Qualifier 注解