本文整理汇总了PHP中curl::get_raw_response方法的典型用法代码示例。如果您正苦于以下问题:PHP curl::get_raw_response方法的具体用法?PHP curl::get_raw_response怎么用?PHP curl::get_raw_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curl
的用法示例。
在下文中一共展示了curl::get_raw_response方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download_file_content
//.........这里部分代码省略.........
}
$curl = new curl();
$curl->setHeader($headers2);
$options['CURLOPT_RETURNTRANSFER'] = true;
$options['CURLOPT_NOBODY'] = false;
$options['CURLOPT_TIMEOUT'] = $timeout;
if ($tofile) {
$fh = fopen($tofile, 'w');
if (!$fh) {
if ($fullresponse) {
$response = new stdClass();
$response->status = 0;
$response->headers = array();
$response->response_code = 'Can not write to file';
$response->results = false;
$response->error = 'Can not write to file';
return $response;
} else {
return false;
}
}
$options['CURLOPT_FILE'] = $fh;
}
if (isset($postdata)) {
$content = $curl->post($url, $postdata, $options);
} else {
$content = $curl->get($url, null, $options);
}
if ($tofile) {
fclose($fh);
@chmod($tofile, $CFG->filepermissions);
}
/*
// Try to detect encoding problems.
if ((curl_errno($ch) == 23 or curl_errno($ch) == 61) and defined('CURLOPT_ENCODING')) {
curl_setopt($ch, CURLOPT_ENCODING, 'none');
$result = curl_exec($ch);
}
*/
$info = $curl->get_info();
$error_no = $curl->get_errno();
$rawheaders = $curl->get_raw_response();
if ($error_no) {
$error = $content;
if (!$fullresponse) {
debugging("cURL request for \"{$url}\" failed with: {$error} ({$error_no})", DEBUG_ALL);
return false;
}
$response = new stdClass();
if ($error_no == 28) {
$response->status = '-100';
// Mimic snoopy.
} else {
$response->status = '0';
}
$response->headers = array();
$response->response_code = $error;
$response->results = false;
$response->error = $error;
return $response;
}
if ($tofile) {
$content = true;
}
if (empty($info['http_code'])) {
// For security reasons we support only true http connections (Location: file:// exploit prevention).
$response = new stdClass();
$response->status = '0';
$response->headers = array();
$response->response_code = 'Unknown cURL error';
$response->results = false;
// do NOT change this, we really want to ignore the result!
$response->error = 'Unknown cURL error';
} else {
$response = new stdClass();
$response->status = (string) $info['http_code'];
$response->headers = $rawheaders;
$response->results = $content;
$response->error = '';
// There might be multiple headers on redirect, find the status of the last one.
$firstline = true;
foreach ($rawheaders as $line) {
if ($firstline) {
$response->response_code = $line;
$firstline = false;
}
if (trim($line, "\r\n") === '') {
$firstline = true;
}
}
}
if ($fullresponse) {
return $response;
}
if ($info['http_code'] != 200) {
debugging("cURL request for \"{$url}\" failed, HTTP response code: " . $response->response_code, DEBUG_ALL);
return false;
}
return $response->results;
}