function getUrlRespHtml($url) { printAutoNewline("now to get response from url=" . $url); //get the file (e.g. image) and output it to the browser $ch = curl_init(); //open curl handle curl_setopt($ch, CURLOPT_URL, $url); //set an url curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //do not output directly, use variable curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //do a binary transfer curl_setopt($ch, CURLOPT_FAILONERROR, 1); //stop if an error occurred $response = curl_exec($ch); //store the content in variable if (!curl_errno($ch)) { //send out headers and output header("Content-type: " . curl_getinfo($ch, CURLINFO_CONTENT_TYPE) . ""); header("Content-Length: " . curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD) . ""); //printAutoNewline($response); } else { printAutoNewline('Curl error: ' . curl_error($ch)); } curl_close($ch); //close curl handle return $response; }
function getUrlRespHtml($url) { printAutoNewline("now to get response from url=" . $url); //get the file (e.g. image) and output it to the browser $ch = curl_init(); //open curl handle curl_setopt($ch, CURLOPT_URL, $url); //set an url curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //do not output directly, use variable curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //do a binary transfer curl_setopt($ch, CURLOPT_FAILONERROR, 1); //stop if an error occurred curl_setopt($ch, CURLOPT_AUTOREFERER, 1); //当根据Location:重定向时,自动设置header中的Referer:信息。 #printAutoNewline("now add CURLOPT_COOKIEJAR support"); $cookieJarFilename = "cookie_jar.txt"; //$cookieJarFullname = dirname(__FILE__).$cookieJarFilename; $cookieJarFullname = concatenatePath(dirname(__FILE__), $cookieJarFilename); printAutoNewline("cookieJarFullname=" . $cookieJarFullname); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJarFullname); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieJarFullname); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); $requestHeader[0] = "Accept: text/html, application/xhtml+xml, */*,"; //$requestHeader[] = "Cache-Control: max-age=0"; $requestHeader[] = "Connection: keep-alive"; //$requestHeader[] = "Keep-Alive: 300"; //$requestHeader[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; //$requestHeader[] = "Accept-Language: en-us,en;q=0.5"; //$requestHeader[] = "Pragma: "; // browsers keep this blank. curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeader); $response = curl_exec($ch); //store the content in variable if (!curl_errno($ch)) { //send out headers and output header("Content-type: " . curl_getinfo($ch, CURLINFO_CONTENT_TYPE) . ""); header("Content-Length: " . curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD) . ""); //printAutoNewline($response); } else { printAutoNewline('Curl error: ' . curl_error($ch)); } curl_close($ch); //close curl handle return $response; }