해결 file_get_콘텐츠가 https 연결을 요청할 수 없는 방법
1849 단어 file get contentshttps 연결
솔루션은 다음과 같습니다.
1. 윈도우즈 아래의 PHP는 php까지만 가능합니다.ini에서 extension=php_openssl.dll 앞의 것;지우고 서비스를 다시 시작하면 됩니다.
2. linux 아래의 PHP는 반드시 Openssl 모듈을 설치해야 합니다. 설치가 다 된 후에 접근할 수 있습니다.
3. 서버에서 설정을 수정할 수 없으면curl 함수를 사용하여 file_get_콘텐츠 함수, 물론 간단한 교체는 아니죠.상응하는 매개 변수 설정이 있어야curl 함수를 정상적으로 사용할 수 있습니다.
curl 함수에 대한 패키지는 다음과 같습니다.
function http_request($url,$timeout=30,$header=array()){
if (!function_exists('curl_init')) {
throw new Exception('server not install curl');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (!emptyempty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
$data = curl_exec($ch);
list($header, $data) = explode("\r
\r
", $data);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 301 || $http_code == 302) {
$matches = array();
preg_match('/Location:(.*?)
/', $header, $matches);
$url = trim(array_pop($matches));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
}
if ($data == false) {
curl_close($ch);
}
@curl_close($ch);
return $data;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
file_ 정보get_콘텐츠가 비어 있거나 함수가 사용할 수 없는 해결 방안으로 되돌아오기하면, 만약, 만약...get_콘텐츠가 원격 파일의 내용을 비어 있거나 이 함수를 사용할 수 없음을 알려 줍니다. 아마도 본문은 당신을 도울 수 있을 것입니다!file_ 사용하기get_contents와 fopen은 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.