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

后端 未结 5 623
情书的邮戳
情书的邮戳 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:26

    Ideally getting your post data could be accomplished with a simple Bind() call. However, I've seen inconsistent results when using a Bind in a post call such that I've resorted to using the scheme outlined above.

    I've seen various discussions about Nancy Bind() working and not working... I've seen both with Post but cannot explain the inconsistency. Where I saw it function properly was where I could guarantee the body of the request was managed as follows:

            var data = Encoding.ASCII.GetBytes (postData);
    
            request.Method = "POST";
            request.ContentType = "application/json";
            request.ContentLength = data.Length;
    
            using (var stream = request.GetRequestStream ()) {
                stream.Write (data, 0, data.Length);
            }
    

    However, when sending data that should have been similarly handled (though I couldn't confirm) through WSO2 infrastructure (data serialized as a JSON event dictionary sent to a service proxy), Bind failed while the method above succeeded.

提交回复
热议问题