Using REST with Basic Auth and a FormUrlEncoded payload with multiple 'text' entries (essentially, a word document represented as 8 sentences), when I call the API it returns the translations, but it returns the first sentence twice leaving the translated array out of sync with the initial request. Is there something basic that I'm missing? I am stuck on .net40 too.
var payload = new FormUrlEncodedContent(watsonValues);
var translationResponse = _watsonClient.PostAsync($"{_watsonBase}/v2/translate", payload).Result;
if (translationResponse.IsSuccessStatusCode)
{
var responsePayload = translationResponse.Content.ReadAsStringAsync().Result;
var watsonTranslations = JsonConvert.DeserializeObject<WatsonMtResponse>(responsePayload);
foreach (var translation in watsonTranslations.Translations)
{
translatedList.Add(translation.Translation);
}
}
else
{
translationResponse.EnsureSuccessStatusCode();
}
I addressed the issue by making the request Json based rather than the FormUrlEncoded request I made previously. The code is basically...
var translationResponse = _watsonClient.PostAsync($"{_watsonBase}/v2/translate",
new StringContent(JsonConvert.SerializeObject(mtRequest),
Encoding.UTF8,
"application/json"))
.Result;
if (translationResponse.IsSuccessStatusCode)
{
var responsePayload = translationResponse.Content.ReadAsStringAsync().Result;
var watsonTranslations = JsonConvert.DeserializeObject<WatsonMtResponse>(responsePayload);
foreach (var translation in watsonTranslations.Translations)
{
translatedList.Add(translation.Translation);
}
}
else
{
translationResponse.EnsureSuccessStatusCode();
}
And the Json object looks like this...
class WatsonMtRequest
{
[JsonProperty("model_id")]
public string ModelId { get; set; }
[JsonProperty("text")]
public List<string> Text { get; set; }
}