Don't get full Json C#


#1

I don’t get the full Json when I make a request to the Twitter API with C#. I use the following code:

public static async Task<string> GetTwitterList(string bearerToken)
        {
            WebRequest request = WebRequest.Create("https://api.twitter.com/1.1/lists/show.json?slug=odyssee&owner_screen_name=dieVanDeIlias");

            request.Method = "GET";
            request.Headers.Add("Authorization", String.Format("Bearer {0}", bearerToken));
            request.Timeout = Timeout.Infinite;
                
            WebResponse response = await request.GetResponseAsync();

            Stream reponseStream = response.GetResponseStream();

            Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");

            StreamReader readStream = new StreamReader(reponseStream, encoder);
            Char[] read = new Char[256];

            int count = readStream.Read(read, 0, 256);

            String str = "000";

            while (count > 0)
            {
                str = new String(read, 0, count);
                count = readStream.Read(read, 0, 256);
            }

            readStream.Close();
            response.Close();

            return str;
        }

#2

Solved with using Stream.ReadToEnd():

public static async Task GetTwitterList(string bearerToken)
{
WebRequest request = WebRequest.Create(“https://api.twitter.com/1.1/lists/statuses.json?slug=odyssee&owner_screen_name=dieVanDeIlias”);

        string result = "";

        request.Method = "GET";
        request.Headers.Add("Authorization", String.Format("Bearer {0}", bearerToken));
        request.Timeout = Timeout.Infinite;
            
        WebResponse response = await request.GetResponseAsync();

        Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");

        string contentLength = response.Headers.Get("Content-Length");
        int contentLengthInt = Convert.ToInt32(contentLength);

        using (StreamReader sr = new StreamReader(response.GetResponseStream(), encoder))
        {
            while (sr.Peek() >= 0)
            {
                result = sr.ReadToEnd();
            }
        }

        return result;
    }