public

  • Download Gist
200_request_response.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Request:
----------------------------------------------------------------------------
GET http://localhost:49207/api/cars HTTP/1.1
User-Agent: Fiddler
Host: localhost:49207
Accept: application/json
 
Response:
----------------------------------------------------------------------------
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcYXBwc1xAcG9zdHNcQ29ubmVnV2l0aEV4Y2x1ZGVNYXRjaE9uVHlwZU9ubHlcQ29ubmVnV2l0aEV4Y2x1ZGVNYXRjaE9uVHlwZU9ubHlcYXBpXGNhcnM=?=
X-Powered-By: ASP.NET
Date: Thu, 21 Jun 2012 20:14:09 GMT
Content-Length: 17
 
["Car 1","Car 2"]
406_request_response.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Request:
----------------------------------------------------------------------------
GET http://localhost:49207/api/cars HTTP/1.1
User-Agent: Fiddler
Host: localhost:49207
 
Response:
----------------------------------------------------------------------------
HTTP/1.1 406 Not Acceptable
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcYXBwc1xAcG9zdHNcQ29ubmVnV2l0aEV4Y2x1ZGVNYXRjaE9uVHlwZU9ubHlcQ29ubmVnV2l0aEV4Y2x1ZGVNYXRjaE9uVHlwZU9ubHlcYXBpXGNhcnM=?=
X-Powered-By: ASP.NET
Date: Thu, 21 Jun 2012 20:13:02 GMT
Content-Length: 0
Global.asax.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
protected void Application_Start(object sender, EventArgs e) {
 
var config = GlobalConfiguration.Configuration;
var routes = config.Routes;
 
// From DefaultContentNegotiator class:
// If ExcludeMatchOnTypeOnly is true then we don't match on type only which means
// that we return null if we can't match on anything in the request. This is useful
// for generating 406 (Not Acceptable) status codes.
config.Services.Replace(
typeof(IContentNegotiator),
new DefaultContentNegotiator(excludeMatchOnTypeOnly: true)
);
 
routes.MapHttpRoute(
"DefaultHttpRoute",
"api/{controller}/{id}",
new { id = RouteParameter.Optional }
);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.