As Header add Authorization
-
The next problem has arisen, I'm trying to integrate with the service to get English translations. So that's why I can use them first, you need to get Bearer-Token. To get it, I have to go through the copying. Screen dock is attached below.
He wrote the following code:
private readonly string _apiKey = "OGZjODBmM2ItZmM3Mi00YjY4LWE4ODUtZTVlNGQ0NDI5MmFhOjhkN2M3YzIyMzA1NTRhZThiNWJmYmRlODBlYmY1NjZj"; private readonly string _url = "https://developers.lingvolive.com"; private readonly HttpClient _httpClient;
public ExternalApi() { _httpClient = new HttpClient(); } public async Task AuthorizationAsync(CancellationToken cancellationToken = default) { using var request = new HttpRequestMessage(HttpMethod.Post, $"{_url}/api/v1.1/authenticate"); request.Headers.Authorization = new AuthenticationHeaderValue($"Basic {_apiKey}"); using var response = await _httpClient.SendAsync(request, cancellationToken); }
If the method is called, I get a mistake.
System.FormatException: "The format of value 'Basic OGZjODBmM2ItZmM3Mi00YjY4LWE4ODUtZTVlNGQ0NDI5MmFhOjhkN2M3YzIyMzA1NTRhZThiNWJmYmRlODBlYmY1NjZj' is invalid."
-
Decided the problem.
request.Headers.Authorization = new AuthenticationHeaderValue("Basic",_apiKey);