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


相关推荐
XH-hui2 分钟前
【打靶日记】VulNyx 之 Responder
linux·网络安全·vulnyx
weixin_307779132 分钟前
Jenkins Branch API插件详解:多分支项目管理的核心引擎
java·运维·开发语言·架构·jenkins
赖small强5 分钟前
【Linux驱动开发】 Linux `/proc` 虚拟文件系统深度解析与实战指南
linux·驱动开发·/proc·/proc/sys`·/proc/net
HalvmånEver10 分钟前
Linux:进程创建(进程控制一)
linux·运维·服务器·学习·进程·fork
陈聪.11 分钟前
MySQL全平台安装指南:Windows与Linux详细教程
linux·windows·mysql
云飞云共享云桌面19 分钟前
佛山某机械加工设备工厂10个SolidWorks共享一台服务器的软硬件
大数据·运维·服务器·前端·网络·人工智能·性能优化
BullSmall23 分钟前
日志安全:严禁记录的敏感信息清单
运维·服务器·安全
卡次卡次125 分钟前
注意点:多线程与多进程与在并行读-->并行cpu或者GPU处理--->并行写 的架构中,如何选择
linux·网络·python
vortex528 分钟前
基于 Apache 规则拦截目录扫描器请求:实测与配置指南
linux·网络安全·apache