php将curl相关操作封装成方法解决办法
内容摘要
这篇文章主要为大家详细介绍了php将curl相关操作封装成方法简单示例,具有一定的参考价值,可以用来参考一下。
对php将curl相关操作封装成方法简单示例对此感兴趣的朋友,看看id
对php将curl相关操作封装成方法简单示例对此感兴趣的朋友,看看id
文章正文
这篇文章主要为大家详细介绍了php将curl相关操作封装成方法简单示例,具有一定的参考价值,可以用来参考一下。
对php将curl相关操作封装成方法简单示例对此感兴趣的朋友,看看idc笔记做的技术笔记!
/**
*
* @param
* @arrange (www.idcnote.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);
注:关于php将curl相关操作封装成方法简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释