php curl详解

http://www.cnblogs.com/CHEUNGKAMING/p/5717429.html

post参数为多维数组时解决方法

http://www.jb51.net/article/75112.htm

 

注意post和get数据获取的区别

get

//初始化
  $ch = curl_init();

 

  //设置选项,包括URL
  curl_setopt($ch, CURLOPT_URL, "http://www.jb51.net");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);

  //执行并获取HTML文档内容
  $output = curl_exec($ch);

  //释放curl句柄
  curl_close($ch);

  //打印获得的数据
  print_r($output);

Post

$url = "http://localhost/web_services.php";
  $post_data = array ("username" => "bob","key" => "12345");

 

  $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);

  $output = curl_exec($ch);
  curl_close($ch);

  //打印获得的数据
  print_r($output);

posted @ 2017-09-25 13:56  LvFish  阅读(192)  评论(0编辑  收藏  举报