Ball Lê
Ball Lê

Reputation: 1

How to create HttpWebRequest to Varnish Cache Server on Ubuntu?

I am using ASP.NET and IIS for my website. Recently, I found Varnish Cache software via Google, an excellent caching HTTP reverse proxy.

Varnish Cache is installed on Ubuntu 16.04.1 and then I configure IIS connect to it. That's great.

Varnish Cache has function Purge to clear all cache of a specify page or all site. On ASP.NET, I wrote code create a Request to Varnish Cache Server with method PURGE and error occur: The remote server returned an error: (405) Method Not Allowed.

Here is my code:

  HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://IP-Address-Varnish-Cache-Server");
  req.Method = "PURGE";
  using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
  {
    // get the page data
    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
    {
      string html = sr.ReadToEnd();
    }
  }

Please help me how to fix above error ? Thanks.

Upvotes: 0

Views: 513

Answers (1)

Pawel
Pawel

Reputation: 380

It is rather an old topic, but it looks like Your Varnish have kind of whitelist to allow only few sources (IP addresses) that can PURGE Your varnish. Take a look at docs

Upvotes: 0

Related Questions