这篇文章主要为大家详细介绍了php将curl相关操作封装成方法简单示例,具有一定的参考价值,可以用来参考一下。
对php将curl相关操作封装成方法简单示例感兴趣的小伙伴,下面一起跟随四海网的小编巴闭妹来看看吧!
/**
*
* @param
* @arrange (512.笔记) www.q1010.com
**/
function curl_request($url, $sim = true, $method = "get", $postfields = NULL) {
$sim or $url .= "&sim_request=1";
$ci = curl_init ();
curl_setopt ( $ci, CURLOPT_URL, $url );
curl_setopt ( $ci, CURLOPT_HEADER, FALSE );
curl_setopt ( $ci, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ci, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT'] );
curl_setopt ( $ci, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt ( $ci, CURLOPT_SSL_VERIFYHOST, 0 );
if ('post' == strtolower ( $method )) {
curl_setopt ( $ci, CURLOPT_POST, TRUE );
if (is_array ( $postfields )) {
$field_str = "";
foreach ( $postfields as $k => $v ) {
$field_str .= "&$k=" . urlencode ( $v );
}
curl_setopt ( $ci, CURLOPT_POSTFIELDS, $field_str );
}
}
$response = curl_exec ( $ci );
if (curl_errno ( $ci )) {
throw new Exception ( curl_error ( $ci ), 0 );
} else {
$httpStatusCode = curl_getinfo ( $ci, CURLINFO_HTTP_CODE );
if (200 !== $httpStatusCode) {
throw new Exception ( $response, $httpStatusCode );
}
}
curl_close ( $ci );
return $response;
}
$param=array();
$param['username'] = rtrim($users[$i],"\r");
$param['action']='deleteuser';
$url = $aduseropt_url."/ldapInterface.php";
$res = curl_request($url,true,'post',$param);
本文来自:http://www.q1010.com/173/11078-0.html
注:关于php将curl相关操作封装成方法简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。