Problems with carret in URL (real time ticker sample)

M

Mikeerh

I have a ticker sample running with yahoo as provider.
When it comes to indices they all start with a caret (^) like ^DJI.
The framework converts this string internally into a %% before it is on the
net (I saw it with wireshark) and than yahoo responds with a N/A ??
How can I get the framework to let the carret through??

here is the sample code:

?using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace YahooTicker
{
class Program
{


private static void Main(string[] args)
{
string ticker = "^DJI";
Uri siteUri = new Uri("http://quote.yahoo.com/d/quotes.csv?s=" +
ticker + "&f=sl1d1t1c1ohgvj1pp2owern&e=.csv");

WebClient web = new WebClient();
string data = web.DownloadString(siteUri);

Quote q = Quote.Parse(data);

Console.WriteLine(string.Format("{0} {1} Last:{2} Change:{3}
Bid:{4} Offer: {5}", q.Ticker, q.Name, q.Last, q.Change, q.Bid, q.Offer));
Console.ReadLine();
}
}

public class Quote
{
public double Last { get; set; }
public string Ticker { get; set; }
public double Change { get; set; }
public string Name { get; set; }
public double Bid { get; set; }
public double Offer { get; set; }

public static Quote Parse(string data)
{
string[] fields = data.Replace("\"", "").Split(',');
Quote q = new Quote
{
Ticker = fields[0].ToUpper(),
Last = Convert.ToDouble(fields[1]),
Change = Convert.ToDouble(fields[4]),
Bid = Convert.ToDouble(fields[5]),
Offer = Convert.ToDouble(fields[6]),
Name = fields[7].ToUpper()
};

return q;
}
}
 
A

Andrew Morton

Mikeerh said:
I have a ticker sample running with yahoo as provider.
When it comes to indices they all start with a caret (^) like ^DJI.
The framework converts this string internally into a %% before it is
on the net (I saw it with wireshark) and than yahoo responds with a
N/A ?? How can I get the framework to let the carret through??

here is the sample code:
string ticker = "^DJI";
Uri siteUri = new Uri("http://quote.yahoo.com/d/quotes.csv?s=" + ticker +
"&f=sl1d1t1c1ohgvj1pp2owern&e=.csv");

Have you tried ... + Server.UrlEncode(ticker) + ...?

Andrew
 
A

Andrew Morton

Mikeerh said:
I have a ticker sample running with yahoo as provider.
When it comes to indices they all start with a caret (^) like ^DJI.
The framework converts this string internally into a %% before it is
on the net (I saw it with wireshark) and than yahoo responds with a
N/A ?? How can I get the framework to let the carret through??

here is the sample code:
string ticker = "^DJI";
Uri siteUri = new Uri("http://quote.yahoo.com/d/quotes.csv?s=" + ticker +
"&f=sl1d1t1c1ohgvj1pp2owern&e=.csv");

Have you tried ... + Server.UrlEncode(ticker) + ...?

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top