Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1183631
  • 博文数量: 252
  • 博客积分: 5421
  • 博客等级: 大校
  • 技术积分: 2418
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-17 12:59
文章分类

全部博文(252)

文章存档

2017年(3)

2016年(18)

2015年(31)

2014年(18)

2013年(7)

2012年(8)

2011年(12)

2010年(30)

2009年(32)

2008年(57)

2007年(36)

分类: 系统运维

2012-11-29 20:56:54


  1. function curl_post($strUrl, $arrData=array(), $boolUseCookie=false)
  2. {
  3.     $strData = array();
  4.     foreach ($arrData as $k => $v) {
  5.         $strData[] = "$k=$v";
  6.     }
  7.     $strData = $strData ? implode('&', $strData) : '';
  8.     $ch = curl_init($strUrl);
  9.     curl_setopt($ch, CURLOPT_HEADER, 0);
  10.     curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  11.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  12.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  13.     curl_setopt($ch, CURLOPT_POST, true);
  14.     curl_setopt($ch, CURLOPT_POSTFIELDS, $strData);
  15.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  16.     curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
  17.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  18.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  19.     if ($boolUseCookie && is_array($_COOKIE) && count($_COOKIE) > 0) {
  20.         $cookie_str = '';
  21.         foreach($_COOKIE as $key => $value) {
  22.             $cookie_str .= "$key=$value; ";
  23.         }
  24.         curl_setopt($ch, CURLOPT_COOKIE, $cookie_str);
  25.     }
  26.     $response = curl_exec($ch);
  27.     if (curl_errno($ch) != 0) {
  28.         //echo curl_error($ch);
  29.         return false;
  30.     }
  31.     curl_close($ch);
  32.     return $response;
  33. }

阅读(2250) | 评论(0) | 转发(0) |
0

上一篇:python daemon

下一篇:windows命令行设置ip地址

给主人留下些什么吧!~~