Creating a proxy with ApiController

I’ve recently moved to MVC 4, and as part of the clean up work I’ve moved a lot of methods I use for AJAX operations to the new ASP.NET Web API, on controllers that inherit from ApiController.

When it came to migrate a proxy action, I was amazed to find how much easier it is to build a proxy, with the method only taking a couple of lines.

A couple of notes on what’s in here:

  1. Ideally I wouldn’t be modifying the original Request object, I’d really like to copy it into a new instance, but I couldn’t find a way to easily do it.
  2. I’m not 100% sure why, but for GET requests the Content property is not null which causes HttpClient to error with a protocol violation exception.

– Phil

Comments are closed.