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

时间:2018-06-14 15:26:21

标签: python python-3.x aiohttp

我们正在使用aiohttp向各种网站供应商发出多个请求以获取最新数据。

某些内容提供商从缓存中提供数据。是否可以直接从服务器请求数据?我们试图传递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() 参数而没有运气。

last-modified date header

目标是获取缓存请求未提供的{{1}}。

1 个答案:

答案 0 :(得分:0)

尝试将一些具有动态值的其他变量添加到网址(例如时间戳记)。 即使它忽略Cache-Control,这也可以防止在服务器端进行缓存。

示例:
来自:https://example.com/test
到:https://example.com/test?timestamp=20180724181234