简体   繁体   English

如何使用aiohttp向外部服务器发出客户端请求以避免缓存

[英]How to make client request to external server avoiding cache using aiohttp

We are using aiohttp to make multiple requests to various website vendors to grab their latest data. 我们正在使用aiohttp向多个网站供应商发出多个请求,以获取其最新数据。

Some of the content providers serve the data from a cache. 一些内容提供者从缓存中提供数据。 Is it possible to request the data from the server directly? 是否可以直接从服务器请求数据? We have tried to pass in the headers parameter with no luck. 我们尝试传递headers参数没有任何运气。

async def fetch(url):
    global response
    headers = {'Cache-Control': 'no-cache'}
    async with ClientSession() as session:
        async with session.get(url, headers=headers, proxy="OUR-PROXY") as response:
            return await response.read()

The goal is to get the last-modified date header , which is not provided from the cache request. 目标是获取last-modified date header ,而缓存请求未提供该last-modified date header

Try to add some additional variable with dynamic value to URL (eg timestamp). 尝试将一些具有动态值的其他变量添加到URL(例如时间戳)。 This will prevent caching on the server side even if it ignores Cache-Control. 即使它忽略Cache-Control,这也将防止在服务器端进行缓存。

Example: 例:
from: https://example.com/test 来自: https : //example.com/test
to: https://example.com/test?timestamp=20180724181234 到: https : //example.com/test?timestamp=20180724181234

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM