R
R
Rasse2020-11-30 15:26:34
C++ / C#
Rasse, 2020-11-30 15:26:34

I send data from WF c# to the site (POST) - to check with the database, how to process the response?

public static async System.Threading.Tasks.Task PostRequestAsync()
        {
            WebRequest request = WebRequest.Create("http://тут сайт");
            request.Method = "POST"; 

            var mbInfo ="p1="+Global.processor()+"&olky=1";

            var scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");

            scope.Connect();

            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(mbInfo);

            request.ContentType = "application/x-www-form-urlencoded";
            // Устанавливаем заголовок Content-Length запроса - свойство ContentLength
            request.ContentLength = byteArray.Length;

            //записываем данные в поток запроса
            using (System.IO.Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }

            WebResponse response = await request.GetResponseAsync();
            
            using (System.IO.Stream stream = response.GetResponseStream())
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
                {

                }
            }

        response.Close();


        }

Something like that in general. And yes I am learning

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2020-11-30
@Rasse

Try to use HttpClient instead of WebRequest (there is a set of extensions for parsing json right away) or Flurl - all the torment will disappear right away.
But if you really want to work with the stream from the response - and pull the deserializer handles, then here: https://docs.microsoft.com/en-us/dotnet/api/system...

R
Rasse, 2020-11-30
@Rasse

The site receives data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question