Marco Dinatsoli
Marco Dinatsoli

Reputation: 10590

Why HttpClient is not opening any page in the browser?

I have a console application and I want to open a asp.net page from it.

I tried this:

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:9000/");
client.GetAsync("http://localhost:9000/");

but when I run the application, nothing in the browser becomes opened.

Upvotes: 2

Views: 2023

Answers (2)

Hamid Pourjam
Hamid Pourjam

Reputation: 20764

you use HttpClient when you want to get or post data programmaticaly. If you want to open an external application in your operating system you should use Process class.

Just start it with the url you want and your operating system will open the default browser for you.

Like this

System.Diagnostics.Process.Start("http://localhost:9000/")

Upvotes: 3

Xi Sigma
Xi Sigma

Reputation: 2372

to open the page in your default browser, you could use

 System.Diagnostics.Process.Start("http://localhost:9000/");

As mentioned in the comments by Dano-o "HttpClient does not have a graphical component, nor does it control a web browser."

Upvotes: 3

Related Questions