https:// osu.ppy.sh/beatmapsets/1012634/download, а затем просто отправил на него веб-запрос и загрузил ответ, но это не совсем сработало, был создан файл размером 200 КБ, который не является битовой картой
а еще я нашел это на GitHub! Проблемы с API https://github.com/ppy/osu-api/issues/288, требующие добавления файлов cookie, но я не уверен, как заставить это работать в С#.
код, который я пробовал:
Код: Выделить всё
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string downloadUrl = "https://osu.ppy.sh/beatmapsets/1012634/download";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(downloadUrl);
if (response.IsSuccessStatusCode)
{
// Read the response content as a byte array
byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
// Save the downloaded file
string filePath = @"C:\Users\chead\Downloads\map.osz";
File.WriteAllBytes(filePath, fileBytes);
Console.WriteLine($"File downloaded successfully to: {filePath}");
}
else
{
Console.WriteLine($"Failed to download file. Status code: {response.StatusCode}");
}
}
Console.WriteLine("That's it!");
Console.ReadKey();
}
}
я также попробовал то, что сказал Загрузить файл с помощью веб-клиента
, но это не сработало p>
вот код, который я пробовал:
Код: Выделить всё
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
WebClient wc = new WebClient();
string strFile = Path.Combine(Directory.GetCurrentDirectory(), "downloaded_file.osz");
wc.Credentials = new System.Net.NetworkCredential("me", "pw");
wc.Headers.Add("User-Agent", "my user agent");
wc.DownloadFile("https://osu.ppy.sh/beatmapsets/1012634/download", strFile);
Console.WriteLine("That's it!");
Console.ReadKey();
}
}
Код: Выделить всё
using System.Net;
class Program
{
static void Main(string[] args)
{
using (var client = new HttpClient())
{
using (var stream = client.GetStreamAsync("https://osu.ppy.sh/beatmapsets/1012634/download"))
{
using (var FileStream = new FileStream("map.osz", FileMode.OpenOrCreate))
{
stream.Result.CopyTo(FileStream);
Console.WriteLine($"Code Returned 0, saved to map.osz in the dir");
}
}
}
Console.ReadKey();
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... in-c-sharp
Мобильная версия