It's the first time I've developed something like this, so I do not know what might be wrong.
I'm making an API call with HttpClient
, like this:
private string autenticar()
{
try
{
using (var client = new HttpClient())
{
string baseUrl = "/geosite-telecom-api/auth/token";
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Mozilla", "5.0"));
var parameters = new Dictionary<string, string> { { "username", Usuario }, { "password", Senha } };
var encodedContent = new FormUrlEncodedContent(parameters);
var retornos = client.PostAsync(Url + baseUrl + $"?username={Usuario}&password={Senha}", encodedContent).Result;
return "";
}
}
catch (Exception ex)
{
throw ex;
}
}
This code above is getting the error:
The underlying connection was closed: Unexpected error in a submission.
I put the return with string
empty so that I can only test the connection to the API per hour.
I tested the URL in SoapUi and got it right.