Usuário com melhor resposta
WebService ou XML cotacao do dollar e bovespa

Pergunta
-
Respostas
-
Fiz o seguinte e funcionou para quem quiser usar!! em breve vou fazer um webservice e disponibilizar para facilitar nossas vidas rs flw
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Threading;
using System.Runtime.Remoting.Messaging;
using System.Net;
using System.IO;public partial class cotacoes : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://www.cotacao.republicavirtual.com.br/web_cotacao.php");
XmlDocument xmlDoc = new XmlDocument();// Define o TimeOut de leitura
wr.Timeout = 10000; // 10 segundos// Lê a resposta
WebResponse resp = wr.GetResponse();
System.IO.Stream stream = resp.GetResponseStream();// Declara uma string para reeber o html
string contents = "";// Preenche a String
using (StreamReader reader = new StreamReader(stream))
{
contents = reader.ReadToEnd().ToString();xmlDoc.LoadXml(contents);
string dolar_comercial_compra = xmlDoc.GetElementsByTagName("dolar_comercial_compra")[0].InnerText.ToString();
string dolar_comercial_venda = xmlDoc.GetElementsByTagName("dolar_comercial_venda")[0].InnerText.ToString();
string dolar_paralelo_compra = xmlDoc.GetElementsByTagName("dolar_paralelo_compra")[0].InnerText.ToString();
string dolar_paralelo_venda = xmlDoc.GetElementsByTagName("dolar_paralelo_venda")[0].InnerText.ToString();
string euro_dolar_compra = xmlDoc.GetElementsByTagName("euro_dolar_compra")[0].InnerText.ToString();
string euro_dolar_venda = xmlDoc.GetElementsByTagName("euro_dolar_venda")[0].InnerText.ToString();lblDolarComeCompr.Text = "Dolar Comercial Compra " + dolar_comercial_compra;
lblDolarComVend.Text = "Dolar Comercial Venda " + dolar_comercial_venda;
lblDolarParaCompr.Text = "Dolar Paralelo Compra " + dolar_paralelo_compra;
lblDolarParaVend.Text = "Dolar Paralelo Venda " + dolar_paralelo_venda;
}
}
catch (Exception ex)
{
// Trata o erro
ex.ToString();}
}
}
Todas as Respostas
-
Faala Felipe,
Dê uma olhada nesse link = http://holococos.sjdr.com.br/dinheiro/cotacao-bovespa/
Testei e funciona legal !!!
Valeu
-
-
Fiz o seguinte e funcionou para quem quiser usar!! em breve vou fazer um webservice e disponibilizar para facilitar nossas vidas rs flw
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Threading;
using System.Runtime.Remoting.Messaging;
using System.Net;
using System.IO;public partial class cotacoes : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://www.cotacao.republicavirtual.com.br/web_cotacao.php");
XmlDocument xmlDoc = new XmlDocument();// Define o TimeOut de leitura
wr.Timeout = 10000; // 10 segundos// Lê a resposta
WebResponse resp = wr.GetResponse();
System.IO.Stream stream = resp.GetResponseStream();// Declara uma string para reeber o html
string contents = "";// Preenche a String
using (StreamReader reader = new StreamReader(stream))
{
contents = reader.ReadToEnd().ToString();xmlDoc.LoadXml(contents);
string dolar_comercial_compra = xmlDoc.GetElementsByTagName("dolar_comercial_compra")[0].InnerText.ToString();
string dolar_comercial_venda = xmlDoc.GetElementsByTagName("dolar_comercial_venda")[0].InnerText.ToString();
string dolar_paralelo_compra = xmlDoc.GetElementsByTagName("dolar_paralelo_compra")[0].InnerText.ToString();
string dolar_paralelo_venda = xmlDoc.GetElementsByTagName("dolar_paralelo_venda")[0].InnerText.ToString();
string euro_dolar_compra = xmlDoc.GetElementsByTagName("euro_dolar_compra")[0].InnerText.ToString();
string euro_dolar_venda = xmlDoc.GetElementsByTagName("euro_dolar_venda")[0].InnerText.ToString();lblDolarComeCompr.Text = "Dolar Comercial Compra " + dolar_comercial_compra;
lblDolarComVend.Text = "Dolar Comercial Venda " + dolar_comercial_venda;
lblDolarParaCompr.Text = "Dolar Paralelo Compra " + dolar_paralelo_compra;
lblDolarParaVend.Text = "Dolar Paralelo Venda " + dolar_paralelo_venda;
}
}
catch (Exception ex)
{
// Trata o erro
ex.ToString();}
}
}
-