Skip to content

Use X HTTP MethodOverride header for DELETE PUT

James Yang edited this page Apr 2, 2019 · 1 revision

Some Wordpress instances do not support DELETE/PUT verbs, so the suggested fallback is to use the X-HTTP-MethodOverride header and send a POST verb instead. You can use RequestFilter to achieve this. Thanks to @lxalln

1. In you project, define filter functions:

        private void RequestFilter(HttpWebRequest request)
        {
            if (request.Method == RequestMethod.DELETE || request.Method == RequestMethod.PUT)
                {
                    request.Headers.Add("X-HTTP-Method-Override", request.Method);
                    request.Method = "POST";
                }
        }

2. Pass filter functions in RestAPI constructor:

var api = new RestAPI("http://www.yourstore.co.nz/wp-json/wc/v3/", "<WooCommerce Key>", "<WooCommerce Secret>", requestFilter: RequestFilter);