c# - ASP.NET Core HTTPRequestMessage returns strange JSON message -


i working asp.net core rc2 , running strange results. have mvc controller following function:

public httpresponsemessage tunnel() {     var message = new httpresponsemessage(httpstatuscode.ok);     message.content = new stringcontent("blablabla", encoding.utf8);     message.content.headers.contenttype = new system.net.http.headers.mediatypeheadervalue("text/plain");     message.headers.cachecontrol = new system.net.http.headers.cachecontrolheadervalue {         nocache = true     };      return message; } 

if call postman accept header set text plain response:

{   "version": {     "major": 1,     "minor": 1,     "build": -1,     "revision": -1,     "majorrevision": -1,     "minorrevision": -1   },   "content": {     "headers": [       {         "key": "content-type",         "value": [           "text/plain"         ]       }     ]   },   "statuscode": 200,   "reasonphrase": "ok",   "headers": [     {       "key": "cache-control",       "value": [         "no-cache"       ]     }   ],   "requestmessage": null,   "issuccessstatuscode": true } 

i not understand how generated reponse above controller. json serialization of entire message , in no way contain "blablabla" intended send.

the way have gotten desired result making controller function return string instead of httpresponse, way unable set headers cachecontrol

so question is: why strange response? seems weird behaviour me

according this article, asp.net core mvc not support httpresponsemessage-returning methods default.

if want keep using it, can, using webapicompatshim:

  1. add reference microsoft.aspnetcore.mvc.webapicompatshim project.
  2. configure in configureservices(): services.addmvc().addwebapiconventions();
  3. set route in configure():

    app.usemvc(routes => {     routes.mapwebapiroute(         name: "default",         template: "{controller=home}/{action=index}/{id?}"); }); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -