php自定义函数: 改进升级版curl
2024-09-28 11:11:31
<?php function dcurl($url, $method = 'GET', $postFields = null, $header = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } switch ($method) { case 'POST': curl_setopt($ch, CURLOPT_POST, true); if (!empty($postFields)) { if (is_array($postFields) || is_object($postFields)) { if (is_object($postFields)) $postFields = Tools::object2array($postFields); $postBodyString = ""; $postMultipart = false; foreach ($postFields as $k => $v) { if ("@" != substr($v, 0, 1)) { //判断是不是文件上传 $postBodyString .= "$k=" . urlencode($v) . "&"; } else { //文件上传用multipart/form-data,否则用www-form-urlencoded $postMultipart = true; } } unset($k, $v); if ($postMultipart) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); } else { curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1)); } } else { curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); } } break; default: if (!empty($postFields) && is_array($postFields)) $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($postFields); break; } } ?>
;
最新文章
- canvas简介
- Guest Speaker on 2015 WinHEC Shenzhen 秋季大会
- EditPlus 3.7.1186 中文版(10月27日更新)重大性能改进,推荐更新!
- RabbitMQ(四)
- FormatMessage与GetLastError配合使用,排查windows api调用过程中的错误
- swagger:The World&#39;s Most Popular Framework for APIs.
- 【CentOS】IBM X3650M4 IMM远程管理【转载】
- C#基础原理拾遗——面试都爱问的委托和事件(纠正)
- visual studio 2015 删除空行 ,缩进css
- 【Hibernate】Illegal attempt to associate a collection with two open sessions
- android在假设绘制自己定义的bitmap,然后返回给ImageView
- cocos2d-x-3.1 经常使用宏 (coco2d-x 学习笔记五)
- hdu--5351--MZL&#39;s Border
- TP-Link路由器的设置向导
- 201521123009 《Java程序设计》第12周学习总结
- 五十九、linux 编程—— I/O 多路复用 fcntl
- SSM结构
- JDK下载与安装、 Eclipse下载与使用、 Tomcat下载与使用、 MySQL安装与使用
- EOF多行写入文件防止变量替换
- ionic_ Network connectivity error occurred, are you offline?