我正在尝试为最终项目构建一个简单的幻想股票JAVA应用程序。目前的主要问题是弄清楚如何检索库存数据。使用Yahoo Finance API检索股票行情
我从雅虎财经Java教程中摘取了这段代码,但它似乎已过时。任何人都会愿意帮助我,并更新httpclient 4.x或将我链接到一个有效的例子吗?
另外,在命令行中,我只需要在-cp或httpcore中引用httpclient?
import java.io.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class YahooWebServiceGet {
public static void main(String[] args) throws Exception {
String request = "http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=umbrella&results=10";
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(request);
// Send GET request
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
InputStream rstream = null;
// Get the response body
rstream = method.getResponseBodyAsStream();
// Process the response from Yahoo! Web Services
BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
看看是否有帮助:http://developer.yahoo.com/search/rest.html。 –