la api que creé me da este resultado:
[
{
"id": 1,
"nombre":"cali"
}
]
y necesito poner el nombre en un combobox por metogo get
mi intento de codigo da error: Error en el servidor remoto: (415) Unsupported Media Type en la linea del form string respuesta = await GetHttp();
internal class usuario
{
public int Id { get; set; }
public string nombre { get; set; }
public string tel { get; set; }
public string dir { get; set; }
public string dir_dat { get; set; }
public int idciudad { get; set; }
public List<usuario> usuarios { get; set; }
}
LLAMADO API
public async void llenarcombo()
{
string respuesta = await GetHttp();
MessageBox.Show(respuesta);
}
private async Task<string> GetHttp() {
string url = "http://localhost:49146/api/usuario";
WebRequest request = WebRequest.Create(url);
WebResponse response = await request.GetResponseAsync();
StreamReader sr = new StreamReader(response.GetResponseStream());
return await sr.ReadToEndAsync();
}
API
[HttpGet]
public JsonResult Get(usuario usu)
{
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
MySqlConnection connection = new MySqlConnection(sqlDataSource);
MySqlCommand myCommand = new MySqlCommand();
myCommand.Connection = connection;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "llenar_ciudad";
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(myCommand);
connection.Open();
DataTable dt = new DataTable();
myDataAdapter.Fill(dt);
return new JsonResult(dt);
}
Lo que está en cuestion es rescatar los datos para meterlos en un ComboBox el cual el usuario escogerá una opcion para registrarse y posterior mente enviarlo a la bd por otra api la cual funciona bien, la appi utiliza una rutina de mysql que cree
intento poner mas detalles para que stack me permita subir toda esa cantidad de codigo que subi y no que que mas escribir, ignoren por completo todo esto es es sol para subiri lo que realmente importa muchas gracias por ayudar.