HttpClient with infinite time out throws time out exception

后端 未结 3 1323
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 18:13

My HttpClient uses digest authentication to connect to the server and expects search queries in response. These search queries can come in any time so the client is expected to

3条回答
  •  忘掉有多难
    2021-02-15 19:00

    I solved this problem in the following way:

    var stream = await response.Content.ReadAsStreamAsync();
        while (b == 1)
        { 
            var bytes = new byte[1];
            try
            {
                var bytesread = await stream.ReadAsync(bytes, 0, 1);
                if (bytesread > 0)
                {
                    text = Encoding.UTF8.GetString(bytes);
    
                    Console.WriteLine(text);
                    using (System.IO.StreamWriter escritor = new System.IO.StreamWriter(@"C:\orden\ConSegu.txt", true))
                    {
                        if (ctext == 100)
                        {
                            escritor.WriteLine(text);
                            ctext = 0;
                        }
                        escritor.Write(text);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("error");
                Console.WriteLine(ex.Message);
            }
        }
    

    in this way I get byte to byte the answer and I save it in a txt later I read the txt and I'm erasing it again. for the moment it is the solution I found to receive the notifications sent to me by the server from the persistent HTTP connection.

提交回复
热议问题