How to log a post into a [closed] Web api]

closed . This question needs details or to be clearer and is not currently accepting answers.

want to improve this question? Add details and make it clearer what problem is being solved by editing this post .

Closed 3 years ago .

improve this question

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

This is the code I'm use.

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);
                }
Author: Marco Souza, 2017-08-29

1 answers

I recommend using Fluent HTTP for this. In addition to being more elegant to perform HTTP requests, there are several other features like this one that 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: http://tmenier.github.io/Flurl/configuration /

 1
Author: Thiago Lunardi, 2017-08-29 09:06:44