c# - RestSharp Accept header change -
i using restsharp developing on client side. using ruby grape gem custom api on server side. grape gem can versioning setting accept http header f.e application/vnd.twitter-v1+json
and test command via console works perfect
curl -h accept=application/vnd.twitter-v1+json /statuses/public_timeline
but when trying set header restrequest getting error 404
on server.
i have no idea why so. have found issue server returns 406 error
- in case 404.
how can put custom value accept header?
you can set custom accept
header addheader
method...
var client = new restclient("http://example.com/api"); var request = new restrequest("statuses/public_timeline", method.get); request.addheader("accept", "application/vnd.twitter-v1+json"); var response = client.execute(request); var json = response.content;
this should work fine if willing deserialize json yourself.
if want make use of generic execute<t>
method, automatic deserialization you, run problems...
from restsharp documentation deserialization:
restsharp includes deserializers process xml , json. upon receiving response, restclient chooses correct deserializer use based on content type returned server. defaults can overridden (see customization). built-in content types supported are:
- application/json – jsondeserializer
- application/xml – xmldeserializer
- text/json – jsondeserializer
- text/xml – xmldeserializer
- * – xmldeserializer (all other content types not specified)
this saying that, default, if response's content type not 1 of listed, restsharp attempt use xmldeserializer on data. customizable though work.
Comments
Post a Comment