Total Downloads

2,598,695

Total Files

9,206

Latest Update

10

How to implement a DelegatingHandler for X-HTTP-Method-Override in Web API

Posted January 29, 2018 | Windows


When deploying your REST Web API over a public domain, you will sometimes encounter problems that are related to support for HTTP verbs. The two challenges in this regard are the limited support for HTTP verbs in old web browsers (i.e. they support only HTTP GET and HTTP POST) and aggressive firewalls that block traffic that is not either an HTTP GET or an HTTP POST. How will your application support a PUT or DELETE in these cases? Here’s exactly where the X-HTTP-Method-Override HTTP header comes to the rescue.

The X-HTTP-Method-Override HTTP header works somewhat similar to a hack. You can add the header with a value of either PUT or DELETE when invoking your Web API via JavaScript or via an XMLHttpRequest object from a web browser using an HTTP POST call. You can then have a delegating handler intercept the HTTP method to be invoked and take the appropriate actions.

In this article I will discuss how we can use a delegating handler in front of the request-response pipeline to alter the request to send a valid message to our application, or alter the response to send back a valid response to the client.

HTTP verbs and delegating handlers

If we are constrained to using only the HTTP verbs GET and POST due to limitations imposed by your client, the web browser, or the firewall fronting your web application, we will have to implement a workaround to support PUT and DELETE. This workaround typically involves adding the X-HTTP-Method-Override HTTP header to the request that specifies the verb we want to use within the HTTP POST call. In addition, we need a delegating handler in our application that checks for the header and, if it exists, makes the call to the HTTP method you want to be invoke.



Source link

')
ankara escort çankaya escort çankaya escort escort bayan çankaya istanbul rus escort eryaman escort ankara escort kızılay escort istanbul escort ankara escort ankara escort escort ankara istanbul rus Escort atasehir Escort beylikduzu Escort Ankara Escort malatya Escort kuşadası Escort gaziantep Escort izmir Escort