Nancy (C#): How do I get my post data?

后端 未结 5 626
情书的邮戳
情书的邮戳 2021-02-07 01:29

I\'m using Corona SDK to post data to my C# server:

headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"
headers[\"Accept-Language\"] = \"en-US\"

l         


        
5条回答
  •  走了就别回头了
    2021-02-07 02:03

    There is a Nancy extension for this. You will need to include the namespace for it.

    using Nancy.Extensions;
    var text =  Context.Request.Body.AsString();
    

    I like how concise this is, part of Nancy's super-duper easy path.

    But a word of caution! This method leaves the stream at the end, so subsequent calls will return empty string. To fix this, always reset the stream immediately afterwards, like so:

    Request.Body.Seek(0, SeekOrigin.Begin);
    

    Nancy 2.0 is supposed to correct this so that the stream position is reset by default.

    https://github.com/NancyFx/Nancy/pull/2158

提交回复
热议问题