How the Web Works

2023-12-27 15:09
文章标签 web works

本文主要是介绍How the Web Works,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Learn Python The Hard Way 书中的相关内容,抄了一遍。
又是一本不可多得的好书。

去年寒假,就是今年一月份,打印了这本书,学了一部分。
三月份在院楼机房花了三星期,大概看完了这本书。
半年后的现在,再看一遍,依然有好多收获。
真的,不用特意寻找特别多的学习资源,好好利用现有的资源。
真的能学好三、两本书。找份工作,没问题的。


I’m start with a simple diagram that shows you the different parts of a web request and how the information flows:

这里写图片描述

I’ve labeled the lines with letters so I can walk you through a regular request process:

  1. You type in the url http://learnpythonthehardway.org/ into your browser and it sends the request out on line (A) to your computer’s network interface.
  2. Your request goes out over the Internet on line (B) and then to the remote computer on line (C) where my server accepts the request.
  3. Once my computer accepts it, my web application get it, and my Python code runs the index.GET handler.
  4. The response comes out of my Python server when I return it, and get back to your browser over line (D) again.
  5. The server running this site takes the response off line (D) then send it back over the Internet on line (C).
  6. The response from the server then comes off the Internet on line (B) , and your computer’s network interface hands it to your browser on line (A).
  7. Finally, your browser then displays the response.

In this description there are a few tems you should know so that you have a common vocabulary to work with when talking about your web application:

Browser
The software that you’re probably using every day. Most people don’t know what it really does, they just call it “the internet”. It’s job is to take addresses (like http://learnpythonthehardway.org ) you type into the URL bar, then use that information to make requests to the server at that address.

Address
This is normally a URL (Uniform Resource Locator) like http://learnpythonthehardway.org/ and indicates where a browser should go. The first part http indicates the protocol you want to use, in this case “Hyper-Text Transport Protocol”. You can also try ftp://ibiblio.org/ to see how “File Transport Protocol” works. The learnpythonthehardway.org part is the “hostname”, ot a human readable address you can remember and which maps to a number called an IP address, similar to a telephone number for a computer on the Internet. Finally, URLs can have a trailing path like the /book/ part of http://learnpythonthehardway.org/book/ which indicates a file or some resource on the server to retrieve with a request. There are many other parts, but those are the main ones.

Connection
Once a browser knows that protocol you want to use (http), what server you want to talk to (learnpythonthehardway.org), and what resource on the server to get, it must take a conection. The browser simply asks your Operating System (OS) to open a “port” to the computer, ususlly port 80. When it works the OS hands back to your program something that works like a file, but is actually sending and receiving bytes over the network wires between your computer and the other computer at “learnpythonthehardway.org”. This is also the same thing that happens with http://localhost:8000/ but in this case you’re telling the browser to connect to your own computer (localhost) and use port 8080 rather than the default of 80. You could also do http://learnpythonthehardway.org:80/ and get the same result, except you’re explicitly saying to use port 80 instead of letting it be that by default.

Request
Your browser is connected using the address you gave. Now it needs to ask for the resource it wants (or you want) on the remote server. If you gave /book/ at the end of the URL, then youwant the file (resource) at /book/, and most servers will use the real file /book/index.html but pretend it doesn’t exist. What the browser does to get this resource is send a request to the server. I won’t get into exactly how it does this, but just understand that it has to send something to query the server for the request. The interesting thing is that these “resources” don’t have to be files. For instance, when the browser in your application asks for something, the server is returning something your Python code generated.

Server
The server is the computer at the end of a browser’s connection that knows how to answer your browser’s requests for files/resources. Most web servers just send files, and that’s actually the majority of traffic. But you’re actually building a server in Python that knows how to take requests for resource, and then return strings that you craft using Python. When you do this crafting, you can pretending to be a file to the browser, but really it’s just code. As you can see from Ex50, it also doesn’t take much code to create a response.

Response
This is the HTML (css, javascript, or images) your server wants to send back to the browser as the answer to the browser’s request. In the case of files, it just reads them off the disk and sends them to the browser, but it wraps the cintents of the disk in a special “header” so the browser knows what it’s getting. In the case of your application, you’re still sending then same thing, including the header, but you generate that data on the fly with your Python code.

这篇关于How the Web Works的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/543541

相关文章

python web 开发之Flask中间件与请求处理钩子的最佳实践

《pythonweb开发之Flask中间件与请求处理钩子的最佳实践》Flask作为轻量级Web框架,提供了灵活的请求处理机制,中间件和请求钩子允许开发者在请求处理的不同阶段插入自定义逻辑,实现诸如... 目录Flask中间件与请求处理钩子完全指南1. 引言2. 请求处理生命周期概述3. 请求钩子详解3.1

SpringBoot项目Web拦截器使用的多种方式

《SpringBoot项目Web拦截器使用的多种方式》在SpringBoot应用中,Web拦截器(Interceptor)是一种用于在请求处理的不同阶段执行自定义逻辑的机制,下面给大家介绍Sprin... 目录一、实现 HandlerInterceptor 接口1、创建HandlerInterceptor实

Web技术与Nginx网站环境部署教程

《Web技术与Nginx网站环境部署教程》:本文主要介绍Web技术与Nginx网站环境部署教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Web基础1.域名系统DNS2.Hosts文件3.DNS4.域名注册二.网页与html1.网页概述2.HTML概述3.

Python使用Reflex构建现代Web应用的完全指南

《Python使用Reflex构建现代Web应用的完全指南》这篇文章为大家深入介绍了Reflex框架的设计理念,技术特性,项目结构,核心API,实际开发流程以及与其他框架的对比和部署建议,感兴趣的小伙... 目录什么是 ReFlex?为什么选择 Reflex?安装与环境配置构建你的第一个应用核心概念解析组件

Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例

《Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例》本文介绍Nginx+Keepalived实现Web集群高可用负载均衡的部署与测试,涵盖架构设计、环境配置、健康检查、... 目录前言一、架构设计二、环境准备三、案例部署配置 前端 Keepalived配置 前端 Nginx

JSON Web Token在登陆中的使用过程

《JSONWebToken在登陆中的使用过程》:本文主要介绍JSONWebToken在登陆中的使用过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录JWT 介绍微服务架构中的 JWT 使用结合微服务网关的 JWT 验证1. 用户登录,生成 JWT2. 自定义过滤

一文教你如何将maven项目转成web项目

《一文教你如何将maven项目转成web项目》在软件开发过程中,有时我们需要将一个普通的Maven项目转换为Web项目,以便能够部署到Web容器中运行,本文将详细介绍如何通过简单的步骤完成这一转换过程... 目录准备工作步骤一:修改​​pom.XML​​1.1 添加​​packaging​​标签1.2 添加

web网络安全之跨站脚本攻击(XSS)详解

《web网络安全之跨站脚本攻击(XSS)详解》:本文主要介绍web网络安全之跨站脚本攻击(XSS)的相关资料,跨站脚本攻击XSS是一种常见的Web安全漏洞,攻击者通过注入恶意脚本诱使用户执行,可能... 目录前言XSS 的类型1. 存储型 XSS(Stored XSS)示例:危害:2. 反射型 XSS(Re

解决JavaWeb-file.isDirectory()遇到的坑问题

《解决JavaWeb-file.isDirectory()遇到的坑问题》JavaWeb开发中,使用`file.isDirectory()`判断路径是否为文件夹时,需要特别注意:该方法只能判断已存在的文... 目录Jahttp://www.chinasem.cnvaWeb-file.isDirectory()遇

JavaWeb-WebSocket浏览器服务器双向通信方式

《JavaWeb-WebSocket浏览器服务器双向通信方式》文章介绍了WebSocket协议的工作原理和应用场景,包括与HTTP的对比,接着,详细介绍了如何在Java中使用WebSocket,包括配... 目录一、概述二、入门2.1 POM依赖2.2 编写配置类2.3 编写WebSocket服务2.4 浏