【发布时间】:2014-05-20 17:55:55
【问题描述】:
我正在开发一个 java 项目,在该项目中我需要生成 url 来获取数据,即来自 yahoo 的开盘价、低价盘、高盘价、收盘价等
类似的帖子here 建议使用来自 java.net.URLEncoder 的 URLEncoder.encode(query, "UTF-8") 但这会生成不同格式的 url。
示例: 对于这个查询
select * from yahoo.finance.historicaldata where symbol in ("YHOO","AAPL") 和 startDate = "2014-01-01" 和 endDate = "2014-02-01"
它给出了网址:
http://query.yahooapis.com/v1/public/yql?q=select+*+from+yahoo.finance.historicaldata+where+symbol+in+%28%22YHOO%22%2C%22AAPL%22%29+and+startDate+%3D+%222014-01-01%22+ and+endDate+%3D+%222014-02-01%22&format=json
而我需要这种格式的网址
https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22)%20and%20startDate%20%3D%20%222014-01- 01%22%20and%20endDate%20%3D%20%222014-02-01%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
请建议我如何将此查询转换为上述网址。
谢谢,
【问题讨论】: