true, CURLOPT_HEADER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_ENCODING => "", // gzip/deflate 対応 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0, // HTTP/2強制(可能なら) ]); $response = curl_exec($ch); if (curl_errno($ch)) { http_response_code(502); echo "取得エラー: " . curl_error($ch); curl_close($ch); exit; } // ヘッダーとボディを分離 $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header_text = substr($response, 0, $header_size); $body = substr($response, $header_size); // Content-Type のみ転送(軽量化のため最小限) if (preg_match('/^Content-Type:\s*(.+)$/im', $header_text, $matches)) { header('Content-Type: ' . trim($matches[1])); } // そのまま出力 echo $body; curl_close($ch); ?>