How to log a post on a web api [closed]

1

I want to know what the Web Api is receiving in the Post that I'm sending.

  

This is the code I'm using.

var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://d6dc30b8-0ee0-4-231-b9ee.azurewebsites.net/");
                    httpWebRequest.Method = "POST";
                    httpWebRequest.ContentType = "application/json";
                    httpWebRequest.Accept = "application/vnd.lyoness.servicesv1 + json";
                    httpWebRequest.Headers.Add("Date" + tempo); 

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();

                }
                MessageBox.Show(json);

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var teste = streamReader.ReadToEnd();
                    MessageBox.Show(teste);
                }
    
asked by anonymous 29.08.2017 / 09:52

1 answer

1

I recommend using Fluent HTTP for this. In addition to being more elegant to perform HTTP requests, there are several other features like the one you need:

FlurlHttp.Configure(c => {
    c.BeforeCallAsync = DoSomethingBeforeCallAsync;
    c.AfterCallAsync = DoSomethingAfterCallAsync;
    c.OnErrorAsync = HandleErrorAsync;
});

To make a POST :

await "http://api.foo.com".PostJsonAsync(new { a = 1, b = 2 });

Source: link

    
29.08.2017 / 11:06