Created
May 8, 2025 17:48
-
-
Save Mark-Uri/c2b52c3127113b94eb8b7cc8e49f5f8a to your computer and use it in GitHub Desktop.
git запрос
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using RestSharp; | |
using System.Text.Json; | |
class Program | |
{ | |
static async Task Main() | |
{ | |
Console.Write("Введите никнейм пользователя GitHub: "); | |
string username = Console.ReadLine(); | |
if (string.IsNullOrWhiteSpace(username)) | |
{ | |
Console.WriteLine("Пусто"); | |
return; | |
} | |
var client = new RestClient("https://api.github.com"); | |
var request = new RestRequest($"users/{username}", Method.Get); | |
request.AddHeader("User-Agent", "CSharpApp"); | |
var response = await client.ExecuteAsync(request); | |
if (!response.IsSuccessful) | |
{ | |
Console.WriteLine("Пользователь не найден"); | |
return; | |
} | |
using var doc = JsonDocument.Parse(response.Content); | |
var root = doc.RootElement; | |
if (root.TryGetProperty("name", out JsonElement nameElement)) | |
{ | |
Console.WriteLine($"Имя пользователя: {nameElement.GetString()}"); | |
} | |
else | |
{ | |
Console.WriteLine("Имя пользователя не указано"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment