$value) { $lowerName = strtolower($name); // 跳过不需要转发的头 if (in_array($lowerName, ['host', 'content-length'])) { continue; } $headers[] = "$name: $value"; } if (!empty($headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } // 执行请求 $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); // 错误处理 if ($error) { http_response_code(502); header('Content-Type: application/json; charset=utf-8'); echo json_encode(['errcode' => -1, 'errmsg' => 'Proxy error: ' . $error]); exit; } // 返回响应 http_response_code($httpCode); header('Content-Type: application/json; charset=utf-8'); echo $response;