常用的curl发包函数
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-22 14:42:55 浏览: 评论:0
- function curl($url, $postFields = null)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_FAILONERROR, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- if (is_array($postFields) && 0 < count($postFields))
- {
- $postBodyString = "";
- foreach ($postFields as $k => $v)
- {
- $postBodyString .= "$k=" . urlencode($v) . "&";
- }
- unset($k, $v);
- curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
- }
- $reponse = curl_exec($ch);
- if (curl_errno($ch)){
- //throw new Exception(curl_error($ch),0);
- ShowMsg("授权出错,请联系管理员","/");
- exit();
- }
- else{
- $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if (200 !== $httpStatusCode){
- //throw new Exception($reponse,$httpStatusCode);
- ShowMsg("授权出错,请联系管理员","/");
- exit(); //phpfensi.com
- }
- }
- curl_close($ch);
- return $reponse;
- }
Tags: curl发包函数 php发包函数
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)