Good afternoon, people.
I'm implementing a function on my system to consume data from a Web Service that requires authentication (Basic Authentication), but I can not get any feedback. The question is whether the authentication mode is correct . I searched here on the same methods website to do this and found the following: insert the link description here insert link description here
Following these two links I created my method that was as follows:
try
{
var authData = string.Format("{0}:{1}", "Usuario", "Senha");
var authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData));
HttpClient cliente = new HttpClient();
var uri = new Uri("https://linkdoService");
cliente.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);
var json = JsonConvert.SerializeObject(usuario, Formatting.Indented);
var content = new StringContent(json, Encoding.UTF8);
var resposta = await cliente.PostAsync(uri, content);
}
The code is not complete because I stop running the application to check what is returning me, and in this case the response variable is always "null". Could someone tell me if this method is correct or am I forgetting something to accomplish this request.
Obs1: I am using the Postman program for testing, when using the URL and the authentication keys, Postman does the normal return, ie, sends a Json and returns a Json as well.
Obs2: I also tested the Json that I am sending to the Web Service, in the case Json created by this line:
var json = JsonConvert.SerializeObject(usuario, Formatting.Indented);
It works normally in Postman.
Thanks in advance for anyone who can help, give a tip.