Returning a string containing valid Json with Nancy

后端 未结 5 576
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 14:05

I receive a string that contains valid JSON from another service. I would like to just forward this string with Nancy but also set the content-type to \"application/json\" which

5条回答
  •  执笔经年
    2021-01-31 14:53

    Pretty much the way you do it. You could do

    var response = (Response)myJsonString;
    response.ContentType = "application/json";
    

    You could just create an extension method on IResponseFormatter and provide your own AsXXXX helper. With the 0.8 release there will be some extensions on the response it self so you can do stuff like WithHeader(..), WithStatusCode() etc-

提交回复
热议问题