Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created June 21, 2012 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugberkugurlu/2968263 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/2968263 to your computer and use it in GitHub Desktop.
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"]
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
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 }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment