Skip to content

MSDOS-Signal/CPPHttpServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

简单的 C++ HTTP 服务器(Windows)

构建(CMake + Visual Studio Build Tools)

  1. 打开“x64 Native Tools Command Prompt for VS”或 PowerShell(已安装 VS 构建工具)。
  2. 在项目根目录执行:
cmake -S . -B build -A x64
cmake --build build --config Release

生成的可执行文件位于:build/Release/SimpleHttpServer.exe(或者 build/SimpleHttpServer.exe,视配置而定)。

运行

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 支持。

About

我自己用C++做的http服务器

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors