Ejemplo n.º 1
0
        // thank you kudu
        private JObject GetPayload(IRequest request)
        {
            JObject payload;

            // we don't care about content type, just let it choked
            if (request.HasFormData)
            {
                var form = request.ReadForm();
                string json = form["payload"];
                if (String.IsNullOrEmpty(json))
                {
                    json = form.First().Value;
                }

                payload = JsonConvert.DeserializeObject<JObject>(json);
            }
            else
            {
                using (JsonTextReader reader = new JsonTextReader(new StreamReader(request.Body)))
                {
                    payload = JObject.Load(reader);
                }
            }

            if (payload == null)
            {
                throw new FormatException("The json payload is empty.");
            }

            return payload;
        }