Curl command without using cache

让人想犯罪 __ 提交于 2020-05-09 18:07:12

问题


Is there a way to tell curl command not to use server's side cache? e.g; I have this curl command:

curl -v www.example.com

how can I ask curl to send a fresh request to not use the cache?

Note: I am looking for an executable command in the terminal.


回答1:


I know this is an older question, but I wanted to post an answer for users with the same question:

curl -H 'Cache-Control: no-cache' http://www.example.com

This curl command servers in its header request to return non-cached data from the web server.




回答2:


The -H 'Cache-Control: no-cache' argument is not guaranteed to work because the remote server or any proxy layers in between can ignore it. If it doesn't work, you can do it the old-fashioned way, by adding a unique querystring parameter. Usually, the servers/proxies will think it's a unique URL and not use the cache.

curl "http://www.example.com?foo123"

You have to use a different querystring value every time, though. Otherwise, the server/proxies will match the cache again. To automatically generate a different querystring parameter every time, you can use date +%s, which will return the seconds since epoch.

curl "http://www.example.com?$(date +%s)"


来源:https://stackoverflow.com/questions/31653271/curl-command-without-using-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!