HttpWebRequest return only partial of data

Hi,
I have a problem with HttpWebRequest. I’m trying to get JSON data from local network server but I’ve get only partial of data (usually first 1069-1070 bytes).

I’m using FezPortal for that projec, and my GET is implemented as below

        private byte[] GetResult = new byte[4 * 1024];

        public string Get(string url)
        {
            int read = 0, total = 0;
            byte[] result = GetResult;

            try
            {
                HttpWebRequest.Create(url);
                using (var req = HttpWebRequest.Create(url) as HttpWebRequest)
                {
                    req.KeepAlive = true;
                    req.ReadWriteTimeout = 10000;
                    req.Timeout = 10000;

                    Thread.Sleep(500);

                    using (var res = req.GetResponse() as HttpWebResponse)
                    {
                        using (var stream = res.GetResponseStream())
                        {
                            do
                            {
                                Thread.Sleep(500);
                                read = stream.Read(result, total, result.Length-total);
                                total += read;
                            }
                            while (read != 0);
                        }
                    }

                    String page = "";

                    page = new String(System.Text.Encoding.UTF8.GetChars(result, 0, total));

                    return page;
                }
            }
            catch (Exception e)
            {
            }
            return null;
        }
    }

BR
KJ

Is it https? If so you need set system time correctly.

No it is http - as I write some data is received, first ~1069 bytes and thats all. Same url I can fetch at web browser and also on ESP32.

Even using TCP socket give same behaviour (TCP connect to 80, then send GET command and in response only partial data is received - mostly HTTP Reply Header - around 1k).
Any help, advice?

I found the issue, in fact there were no issue, everything was working fine, the problem is that debugger get only a biginning from long strings, so in Visual only part of data is visible.

3 Likes