I'm having trouble consuming the data from this WS.
The code I rode is working with another URL, but with this (http://api.promasters.net.br/cotacao/v1/valores) not returning the JSON data.
I tested this URL in the Postman just right and returned the data, but the code is not returning anything.
Could someone give me a hand and see what's going on?
Controller:
public class CotacaoDolar { double valorUsd; public double GetCotacao(double valorBrl) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://api.promasters.net.br/cotacao/v1/valores"); CotacaoModel cotacao = new CotacaoModel(); using (var response = (HttpWebResponse)request.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream())) { JavaScriptSerializer js = new JavaScriptSerializer(); var objText = reader.ReadToEnd(); cotacao = (CotacaoModel)js.Deserialize(objText, typeof(CotacaoModel)); } } foreach (var item in cotacao.valores) { foreach (var val in item.usd) valorUsd = val.valor; } var totalReais = valorBrl * valorUsd; return totalReais; } }
Model:
namespace Models { public class USD { public string nome { get; set; } public double valor { get; set; } public int ultima_consulta { get; set; } public string fonte { get; set; } } public class EUR { public string nome { get; set; } public double valor { get; set; } public int ultima_consulta { get; set; } public string fonte { get; set; } } public class ARS { public string nome { get; set; } public double valor { get; set; } public int ultima_consulta { get; set; } public string fonte { get; set; } } public class GBP { public string nome { get; set; } public double valor { get; set; } public int ultima_consulta { get; set; } public string fonte { get; set; } } public class BTC { public string nome { get; set; } public int valor { get; set; } public int ultima_consulta { get; set; } public string fonte { get; set; } } public class Valores { public List<USD> usd { get; set; } public List<EUR> eur { get; set; } public List<ARS> ars { get; set; } public List<GBP> gbp { get; set; } public List<BTC> btc { get; set; } } public class CotacaoModel { public bool status { get; set; } public List<Valores> valores { get; set; } } }