I have this URL: URL from Google
When open link in new tab, the browser force me download it. After download, I get a text file named \"s\". But I want use C# acces
For asp.net core / .Net 5+, you should inject HttpClient in your service. You should not manually create a new instance.
public class MySerivice {
private readonly HttpClient _httpClient;
public MyService(HttpClient httpClient) {
_httpClient = httpClient;
}
public async Task Foo() {
var myString = await _httpClient.GetStringAsync("https://my-url/file.txt");
}
}
Injecting HttpClient will use IHttpClientFactory behind the scenes. Docs: https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests