✅ api response 401
hey, I'm trying to use nlpcloud to translate text
there is curl example:
I wrote following
everything should be good but I get 401 in
whats wrong with my code?
there is curl example:
curl "https://api.nlpcloud.io/v1/nllb-200-3-3b/translation" \
-H "Authorization: Token <token>" \
-H "Content-Type: application/json" \
-X POST -d '{
"text":"John Doe has been working for Microsoft in Seattle since 1999.",
"source":"en",
"target":"fr"
}'curl "https://api.nlpcloud.io/v1/nllb-200-3-3b/translation" \
-H "Authorization: Token <token>" \
-H "Content-Type: application/json" \
-X POST -d '{
"text":"John Doe has been working for Microsoft in Seattle since 1999.",
"source":"en",
"target":"fr"
}'I wrote following
nlpclientnlpclient:public class NlpTranslationClient
{
private readonly string _apiKey;
private readonly Uri _uri = new("https://api.nlpcloud.io/v1/nllb-200-3-3b/translation");
public NlpTranslationClient(string apiKey)
=> _apiKey = apiKey;
public async Task Translate(
string text,
string source,
string target)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", _apiKey);
var translationObject = new TranslationObj
{
Text = text,
Source = source,
Target = target
};
var payload = new StringContent(
translationObject.ToJson(),
Encoding.UTF8,
"application/json");
var res = await client.PostAsync(_uri, payload); // just for testing
}
}public class NlpTranslationClient
{
private readonly string _apiKey;
private readonly Uri _uri = new("https://api.nlpcloud.io/v1/nllb-200-3-3b/translation");
public NlpTranslationClient(string apiKey)
=> _apiKey = apiKey;
public async Task Translate(
string text,
string source,
string target)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", _apiKey);
var translationObject = new TranslationObj
{
Text = text,
Source = source,
Target = target
};
var payload = new StringContent(
translationObject.ToJson(),
Encoding.UTF8,
"application/json");
var res = await client.PostAsync(_uri, payload); // just for testing
}
}everything should be good but I get 401 in
resres whats wrong with my code?