c# - How to return customer data with HttpResponseMessage -
httpresponsemessage r = new httpresponsemessage(); r.statuscode = httpstatuscode.ok; r.reasonphrase = "success";
now how pass customer object httpresponsemessage
class client side ?
one way return request.createresponse(httpstatuscode.ok, customers);
suppose if not want return response way request.createresponse(httpstatuscode.ok, customers);
rather want create instance of httpresponsemessage
, initialize few property , return. tell me ow pass customer object httpresponsemessage class
client side ?
the simple way should create response based on request:
return request.createresponse(httpstatuscode.ok, customers);
because under hood, method deal content negotiation don't care much. otherwise, have deal manually below code:
icontentnegotiator negotiator = this.configuration.services.getcontentnegotiator(); contentnegotiationresult result = negotiator.negotiate( typeof(customer), this.request, this.configuration.formatters); var response = new httpresponsemessage { statuscode = httpstatuscode.ok, content = new objectcontent<customer>(customer, result.formatter, result.mediatype) }; return response;
Comments
Post a Comment