php curl

curl 模拟post提交

 1 $url = 'http://localhost/url.php';
 2 
 3 $arr = [
 4     'username' => 'Tom',
 5     'age' => 20,
 6     'sex' => '男'
 7 ];
 8 $ch = curl_init();
 9 
10 curl_setopt($ch, CURLOPT_URL, $url);
11 curl_setopt($ch, CURLOPT_HEADER, 0);
12 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
13 curl_setopt($ch, CURLOPT_POST, 1);
14 curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
15 
16 $data = curl_exec($ch);
17 
18 var_dump(json_decode($data));

 

posted @ 2016-03-23 11:28  nikname  阅读(135)  评论(0编辑  收藏  举报