Hej, próbuje ze strony pobrać jej zawartość do pliku typu .txt
W kodzie występuje następujący błąd ( " nie można niejawnie przekonwertować typu "System.IO.Stream" na "string" ) i nie wiem jak go naprawić. Wrzucam wam mój kod:
using System;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net;
using System.IO;
namespace Program
{
class Program
{
public static string fileOutPut = @"C:\Users\Mateusz\source\repos\HTTPClient\HTTPClient\TextFile1.txt";
static void Main(string[] args)
{
Console.WriteLine("Enter the URL that you want an html response from: ");
string url = Console.ReadLine();
var awaiter = CallURL(url);
if (awaiter.Result != "");
{
File.WriteAllText(fileOutPut, awaiter.Result);
Console.WriteLine("HTML Response output to " + fileOutPut);
}
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
public static async Task<string> CallURL(string url)
{
HttpClient client = new HttpClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
client.DefaultRequestHeaders.Accept.Clear();
var response = client.GetStreamAsync(url);
return await response;
}
}
}