I return an empy string when doing this HttpWebRequest

Andreas ss 726 Reputation points
2021-09-22T15:28:36.33+00:00

Hello!

I am trying to do a HttpWebRequest to the below URL. When I do that, I return an empty string.

However, when I put the URL manually in the chrome browser. There is a large JSON string on this URL.

I wonder why I return an empy string with the below URL?

Thank you!

            try
            {
                String URL = "https://api.etherscan.io/api?module=account&action=txlist&address=0xea482c608fedbaebb2bee4456d19acb3270f8355&startblock=12226259&endblock=99999999&sort=asc&apikey=1BDWT2SMX7KPV21FXPT932GZPMX4";

                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
                myRequest.Timeout = 60000;
                myRequest.Method = "GET";
                myRequest.Accept = "application/json";
                myRequest.ContentType = "application/json; charset=utf-8";
                WebResponse myResponse = myRequest.GetResponse();

                var response = (System.Net.HttpWebResponse)myRequest.GetResponse();
                String responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();

                MessageBox.Show(responseString);
            }
            catch(Exception ex) { MessageBox.Show(ex.ToString()); }
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,127 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 86,316 Reputation points
    2021-09-22T16:18:54.733+00:00

    I just tested and the string is not empy

    If you replace the MessageBox by :

    Console.WriteLine(responseString);
    

    it is displayed in the Output window

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.