I'm going through a book to learn more about MVC's WebAPI controllers, and have become stuck on an issue. I'm trying to POST to my WebAPI controller (in Visual Studio 2010) using Fiddler, but am unable to get the connection to my controller.
I have the following class that I'm using per the book:
public class Employee {
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Department { get; set; }
}
My WebApi Controller POST method, with a breakpoint on the first var maxId = ...
line:
public class EmployeesController : ApiController {
public HttpResponseMessage Post(Employee employee) {
var maxId = list.Max(e => e.Id);
employee.Id = maxId + 1;
list.Add(employee);
var response = Request.CreateResponse<Employee>(HttpStatusCode.Created, employee);
string uri = Url.Link("DefaultApi", new { id = employee.Id });
response.Headers.Location = new Uri(uri);
return response;
}
}
I'm able to post a GET through Fiddler2 without issue (rerunning the request that I track from Chrome:
I then tried adjusting the headers to run a POST, and received a 404 while using "localhost" as my server:
Per many suggestions, I tried changing the server to "localhost.", but received the same 404:
I tried one last time with changing from "localhost" to my computer name, and received a 502 instead after it tried to make the post for a second or so (this had the same content as the previous two requests, but only with the above named change to the url):
Per some other recommendations, both in the book and online, I had also added the following to my Web.config in the <configuration>
node before starting on trying any of these POSTS. This resides immediately after the <configSections>
node.
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" bypassonlocal="True" proxyaddress="http://127.0.0.1:8888"/>
</defaultProxy>
</system.net>
Any ideas of what I'm missing? So far in all of my research, this StackOverflow question has been the closest to helping me, but I had already tried the recommendations of the only answer there, and even the video gave me no further insight.
At this point, I would not be surprised if part of it has to do with Visual Studio 2010, unless I've missed something completely simple.