Thursday, July 19, 2018

purging cloudflare cache with an api call in wep api and asp.net C#

Hi All,

Cloudflare's cache

To remove one or more files from Cloudflare's cache either by specifying URLs, faced challenges to integrated the cloud-flare API call. We've tried VS 2015 and framework 4.5.2. Exception through 'upgrade the version' and tried higher version VS 2017 and framework 4.6.1 and its works fine.

Cloudflare Request:


curl -X POST "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/purge_cache" \
     -H "X-Auth-Email: user@example.com" \
     -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
     -H "Content-Type: application/json" \
     --data '{"files":["http://www.example.com/css/styles.css",{"url":"http://www.example.com/cat_picture.jpg","headers":{"Origin":"cloudflare.com","CF-IPCountry":"US","CF-Device-Type":"desktop"}}]}'


Cloudflare Response

{
  "success": true,
  "errors": [],
  "messages": [],
  "result": {
    "id": "9a7806061c88ada191ed06f989cc3dac"
  }
}


Here, Existing application running .net framework 4.5 (immediate need to convert 4.6.1 ), if we change to 4.6.1 version. Required to verify full application and takes 3 to 4 months. Meanstime we think and created web api and call the url in existing application. 

4.5(traditional asp.net)--->4.6.1(web api)---> Cloudflare Purge (Restful API)

Happy coding:)