http

67 阅读1分钟

//HTTP请求(支持HTTP/HTTPS,支持GET/POST)

public static function http_request(url,url, data = null, header=null,header = null ,data_binary = null, get_header=false,get\_header = false, upw = null, auto_proxy=false,auto\_proxy = false, init_call = null,$CUSTOMREQUEST = null)

{

//usleep(15*1000);

$curl = curl_init();

curl_setopt(curl,CURLOPT_URL,curl, CURLOPT\_URL, url);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

if($CUSTOMREQUEST){

curl_setopt(curl,CURLOPT_CUSTOMREQUEST,curl, CURLOPT\_CUSTOMREQUEST, CUSTOMREQUEST);

}

if($upw){

curl_setopt(curl,CURLOPT_USERPWD,curl, CURLOPT\_USERPWD, upw['user'] . ":" . $upw['pw']);

}

if($auto_proxy && USE_PROXY){

curl_setopt($curl, CURLOPT_PROXY, CommonApi::PROXY_IP); //代理服务器地址

curl_setopt($curl, CURLOPT_PROXYPORT, CommonApi::PROXY_PORT); //代理服务器端口

}

if(!empty($data_binary)){

curl_setopt($curl, CURLOPT_POST, 1);

$stream = fopen('php://memory','r+');

fwrite(stream,stream, data_binary );

dataLength=ftell(dataLength = ftell(stream);

rewind($stream);

curl_setopt(curl,CURLOPT_INFILE,curl,CURLOPT\_INFILE,stream);

curl_setopt(curl,CURLOPT_INFILESIZE,curl,CURLOPT\_INFILESIZE,dataLength);

curl_setopt($curl,CURLOPT_UPLOAD,1);

}

else if (!empty($data)) {

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt(curl,CURLOPT_POSTFIELDS,curl, CURLOPT\_POSTFIELDS, data);

}

if ($header) {

curl_setopt(curl,CURLOPT_HTTPHEADER,curl, CURLOPT\_HTTPHEADER, header);

}

if($get_header){

curl_setopt($curl, CURLOPT_HEADER, true);

}

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

// curl_setopt($curl, CURLINFO_HEADER_OUT, true);

if($init_call){

init_call(init\_call(curl);

}

output=curl_exec(output = curl\_exec(curl);

curl_close($curl);

return $output;

}

}