http
缓存

缓存主要分为强缓存和对比缓存。
强缓存
强缓存即是在约定的时间内,不管服务器文件是否更新,都采用缓存文件,返回 200。
max-age= 来设定时间,单位为 s,s-maxage= 为代理服务器的缓存时间。
对比缓存
而对比缓存指,需要和远端文件对比(用 last-modified 和 etag 来实现),如果没有修改返回 304,然后使用缓存;如果有修改,则返回 200,并附带新文件。
aab5d5fd-70c1-11e5-a4fb-b026b977eb28
request 示意
1. application/x-www-form-urlencoded
这种方式通常用于提交简单的表单数据。一个请求示例如下:
1 | |
只有 key 和 value 中的 Non-alphanumeric characters 才会 urlencoded?
2. multipart/form-data
这种方式用于文件上传或需要同时提交文本和文件。一个请求示例如下:
1 | |
3. raw
用于提交原始数据,如JSON。一个请求示例如下:
1 | |
4. binary
直接发送二进制数据,例如,上传一个图片文件。一个请求示例如下:
1 | |
这些文本示意展示了HTTP请求的结构,包括方法(如POST)、路径(如/api或/upload)、主机(如Host: example.com)、内容类型(如Content-Type: application/json)以及请求体(根据提交方式的不同,请求体的格式也不同)。在实际应用中,需要根据服务器的要求和数据的具体情况选择合适的提交方式。
Data from forms is normally encoded using the “media type” application/x-www-form-urlencoded when it doesn’t include files.
But when the form includes files, it is encoded as multipart/form-data. If you use File, FastAPI will know it has to get the files from the correct part of the body.