分享两段PHP代码,超实用POST和GET
2014-10-27 20:26
357 查看
在开发中,我们调用API时经常会用到POST和GET
/* 公用函数 */ if (!function_exists("do_post")){ function do_post($url, $data){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_URL, $url); $ret = curl_exec($ch); curl_close($ch); return $ret; } } if(!function_exists("get_url_contents")){ function get_url_contents($url){ if (ini_get("allow_url_fopen") == "1") return file_get_contents($url); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); return $result; } }
相关文章推荐
- 7个超级实用的PHP代码片段分享
- 7个超级实用的PHP代码片段分享(1)
- php中用socket模拟http中post或者get提交数据的示例代码
- 7个超级实用的PHP代码片段分享
- PHP实用函数:stream_context_create()模拟POST/GET
- php发送get、post请求的6种方法代码示例
- 7个超级实用的PHP代码片段分享 .
- PHP中使用file_get_contents post数据代码例子
- 9个实用的PHP代码片段分享
- 超级实用的7个PHP代码片段分享
- php中用socket模拟http中post或者get提交数据的示例代码
- PHP循环获取GET和POST值的代码
- PHP中使用file_get_contents post数据代码例子
- [PHP代码] 用php的fsocket模拟get提交 模拟post提交表单
- PHP循环获取GET和POST值的代码
- 9个实用的PHP代码片段分享
- php的curl实现get和post的代码
- php的curl实现get和post的代码