Search code examples
c#httpwebrequestarabichttpwebresponseresponsestream

How to read Arabic characters from HttpWebResponse in C#


I'm trying to read my firebase database in C# Application, I'm using HttpWebRequest and response to get the data.

the data in firebase is in Arabic language, when I fetch it in C# Application I see ?????? instead

my code:

static void Main()
    {
        int i = 0;
        Console.WriteLine("here1");
        while (i < 15)
        {
            Console.WriteLine("here0");
            string URL = "<firebasePath>/.json";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            //request.ContentType = "application/json: charset=utf-8";
            //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1);Accept-Language:ar";
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            using (Stream responsestream = response.GetResponseStream())
            {
                StreamReader read = new StreamReader(responsestream, Encoding.UTF8);
                Console.WriteLine(read.ReadToEnd());
               Console.WriteLine("herehere");

                        }
                      i++;
                }
    }

the commented out columns means I have tried this solutions and did not work for me.

example of output:

{"1964":{"2018-05-08 10:48:33":{"activityOneQuestion":"????? ??????? 3 ????? ????????","activityTwoQuestion":"??...

How can I read the Arabic letters ?

Thanks a lot!!


Solution

  • Thanks @VahidN who gave answer in comment, I just want to write it here so it will be easier for everyone to see it.

    Answer:

    Console.WriteLine is not able to show Unicode characters. save it to a file and the examine it

    That worked. Thanks!