-2
I have a service that calls this service:
public async Task<List<Funcionario>> GetFuncionarios()
{
string url = $"http://localhost:56137/api/GetFuncionario";
var response = await client.GetStringAsync(url);
var _funcionario = JsonConvert.DeserializeObject<List<Funcionario>>(response);
return _funcionario;
}
How do I not leave the url sinker in the code, as is?
This way gives me error(I tried to do as the colleague Jjoão passed me)
var webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
string parametro = "GetCidade/{id}";
//if (webConfig.AppSettings.Settings.Count > 0)
//{
var customSetting = webConfig.AppSettings.Settings["serviceApi"];
string url = customSetting?.Value;
var response = await client.GetStringAsync(url + parametro);
var _cidade = JsonConvert.DeserializeObject<List<Cidade>>(response);
return _cidade;
picked it up
An invalid request URI was provided. The request URI must either be an Absolute URI or Baseddress must be set.
When concatenates the
url + parametro
what is the result? Make a Quickwatch and validates the value.– João Martins