博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How the Web Works
阅读量:4100 次
发布时间:2019-05-25

本文共 4855 字,大约阅读时间需要 16 分钟。

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 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 ) 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 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 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 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 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 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.

你可能感兴趣的文章
C++学习之普通函数指针与成员函数指针
查看>>
C++的静态成员函数指针
查看>>
Linux系统编程——线程池
查看>>
yfan.qiu linux硬链接与软链接
查看>>
Linux C++线程池实例
查看>>
shared_ptr简介以及常见问题
查看>>
c++11 你需要知道这些就够了
查看>>
c++11 你需要知道这些就够了
查看>>
shared_ptr的一些尴尬
查看>>
C++总结8——shared_ptr和weak_ptr智能指针
查看>>
c++写时拷贝1
查看>>
C++ 写时拷贝 2
查看>>
Linux网络编程---I/O复用模型之poll
查看>>
Java NIO详解
查看>>
单列模式-编写类ConfigManager读取属性文件
查看>>
java中float和double的区别
查看>>
Statement与PreparedStatement区别
查看>>
Tomcat配置数据源步骤以及使用JNDI
查看>>
before start of result set 是什么错误
查看>>
(正则表达式)表单验证
查看>>