# CPPHttpServer **Repository Path**: signalxh2006/CPPHttpServer ## Basic Information - **Project Name**: CPPHttpServer - **Description**: 我自己用C++做的http服务器 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-07 - **Last Updated**: 2026-06-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 简单的 C++ HTTP 服务器(Windows) ### 构建(CMake + Visual Studio Build Tools) 1. 打开“x64 Native Tools Command Prompt for VS”或 PowerShell(已安装 VS 构建工具)。 2. 在项目根目录执行: ```bash cmake -S . -B build -A x64 cmake --build build --config Release ``` 生成的可执行文件位于:`build/Release/SimpleHttpServer.exe`(或者 `build/SimpleHttpServer.exe`,视配置而定)。 ### 运行 ```bash build/Release/SimpleHttpServer.exe 8080 wwwroot ``` - 第一个参数:端口(可选,默认 8080) - 第二个参数:静态根目录(可选,默认 `wwwroot`) 然后在浏览器访问:`http://localhost:8080/` ### 功能 - 处理 `GET` 请求,返回静态文件 - 简单的内容类型(Content-Type)判断 - 防止基本的路径穿越(阻止 `..`) ### 目录结构 ``` src/ main.cpp http_server.h http_server.cpp wwwroot/ index.html ``` ### 注意 - 仅实现了最基础的 HTTP/1.1 静态服务,适合演示与学习。 - Windows 上使用 Winsock,需要 VS 2019/2022 或 Build Tools 支持。