【Linux网络】应用层协议HTTP

应用层协议HTTP


文章目录


HTTP协议





HTTP协议请求与响应格式





下面是http响应


HTTP响应:


HTTP的方法



代码如下(示例):

c 复制代码
要通过历史写的http服务器,验证GET⽅法, 这⾥需要了解⼀下FORM表单的问题
这⾥就要引⼊web根⽬录,⽂件读取的基本操作了
std::string GetFileContentHelper(const std::string& path)
{
	// ⼀份简单的读取⼆进制⽂件的代码
	std::ifstream in(path, std::ios::binary);
	if (!in.is_open())
		return "";
	in.seekg(0, in.end);
	int filesize = in.tellg();
	in.seekg(0, in.beg);
	std::string content;
	content.resize(filesize);
	in.read((char*)content.c_str(), filesize);
	// std::vector<char> content(filesize);
	// in.read(content.data(), filesize);
	in.close();
	return content;
}

代码如下(示例):

c 复制代码
// curl -i 显⽰
$ curl -i www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 2381
Content-Type: text/html
Date: Sun, 16 Jun 2024 08:38:04 GMT
Etag: "588604dc-94d"
Last-Modified: Mon, 23 Jan 2017 13:27:56 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
<!DOCTYPE html>
...
// 使⽤head⽅法,只会返回响应头
$ curl --head www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 277
Content-Type: text/html
Date: Sun, 16 Jun 2024 08:43:38 GMT
Etag: "575e1f71-115"
Last-Modified: Mon, 13 Jun 2016 02:50:25 GMT
Pragma: no-cache
Server: bfe/1.0.8.18 


HTTP的状态码




HTTP常见Header




cookie 和 session 会话管理和会话保持


相关推荐
甲鱼92915 分钟前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
Johny_Zhao14 小时前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
chlk1232 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑2 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件2 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
不可能的是2 天前
前端 SSE 流式请求三种实现方案全解析
前端·http
深紫色的三北六号3 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash3 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI3 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github