How can I retrieve CSV data from a web server using Flex?
I am trying to retrieve a stock quote from Yahoo! finance using Flex. I currently have it set so that it will pull the quote like I want, but it opens it in a new file. However, I want to store the CSV data in a variable so that I can use it in my program.
How do I do this?
Here is the code that I am using right now:
navigateToURL(new URLRequest("http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1")开发者_开发问答,"_self");
navigateToURL will open a URL from within a Flex application.
Take a look at HTTPService at http://livedocs.adobe.com/flex/3/html/data_access_2.html . It should give you back the results of the HTTP call; which you can than parse and traverse at your leisure.
<mx:HTTPService id="userRequest" url="http://download.finance.yahoo.com
/d/quotes.csv?s=aapl&f=l1" useProxy="false" method="POST" resultFormat="object"
result="{resultEvent(event)}">
public function init() {
userRequest.send()
}
public function resultEvent(event:ResultEvent) {
trace(event.result);
}
On your result event, trace your data.
You can use both mxml tag <mx:httpService>
or AS3 code (urlRequest
and urlLoader
), but I am afraid that the result will not change: if the problem is yahoo's crossdomain.xml
file, or yahoo add an entry to this file or you cannot reverse data directly from yahoo finance on your flex app: I suggest you to call from your flex app a script of yours that get data from yahoo and reverse them into your flex app.
精彩评论