Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

There's another method on WebClient we can use called DownloadString. It takes a string parameter for the URL and return

using System; using System.IO; using System.Net;

namespace Treehouse.CodeChallenges { class Program { static void Main(string[] args) { Console.WriteLine(BecomeZen()); } public static string BecomeZen() { string zenResponse = "";

        using(var webClient = new WebClient())
        {
        webClient.Headers.Add("User-Agent", "CodeChallenge");
        string response = webClient.DownloadString("https://api.github.com/zen");
        }

        return zenResponse;
    }
}

}

it is showing this error guys help out

                                                                                                                                                There's another method on WebClient we can use called DownloadString. It takes a string parameter for the URL and returns the response as a string.

Call the DownloadString method on webClient with the following URL: "https://api.github.com/zen". Assign the result to the zenResponse variable.

Steven Parker
Steven Parker
231,248 Points

It would help to include a link to the course page you are working with. And when posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

1 Answer

using(var webClient = new WebClient()) { webClient.Headers.Add("User-Agent", "CodeChallenge"); zenResponse = webClient.DownloadString("https://api.github.com/zen"); }

    return zenResponse;
}