单次请求的curl方法
public function curlDemo($url, $fields = array(), $method = "post"){
$curl = curl_init();
$fields['app_name'] = 'project_name';
if ( in_array($method, ['get','delete']) && $fields && is_array($fields)) {
$fieldStr = http_build_query($fields);
$url .= '?'.$fieldStr;
}
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_TIMEOUT, 60 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
if(strtolower ( $method ) == "post"){
curl_setopt( $curl, CURLOPT_POST, true);
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query ( $fields ));
} else if(strtolower ( $method ) == "put") {
curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, 'put');
curl_setopt( $curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query ( $fields ));
}