【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 会话管理和会话保持


相关推荐
一个平凡而乐于分享的小比特8 分钟前
Linux最小系统详解
linux·最小系统
db_murphy9 分钟前
学习篇 | 服务器的睿频
运维·服务器·学习
Levin__NLP_CV_AIGC9 分钟前
Ubuntu部署Dufs
linux·运维·服务器·ubuntu·ssh
cly120 分钟前
Ansible自动化(八):条件语句
运维·自动化·ansible
MrYang202020 分钟前
Vcenter vsphere 登录报错
运维·vmware
suamt20 分钟前
记录windows下如何运行docker程序
运维·docker·容器
TOPGUS21 分钟前
谷歌Chrome浏览器即将对HTTP网站设卡:突出展示“始终使用安全连接”功能
前端·网络·chrome·http·搜索引擎·seo·数字营销
小宇的天下23 分钟前
Calibre 3Dstack --每日一个命令days8【connected】(3-8)
运维·服务器·性能优化
ICT系统集成阿祥24 分钟前
服务器网卡绑定(bond)7种模式详解
运维·服务器·bond·网卡绑定·服务器链路聚合
wulalalalalalalal25 分钟前
Linux 内网服务器通过代理访问外网
linux·运维·服务器