Answer the question
In order to leave comments, you need to log in
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();
}
Answer the question
In order to leave comments, you need to log in
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...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question