这个问题在这里已经有答案了:
如何使用post-using-namevaluepair向httpurlconnection添加参数(16个答案)
上个月关门了。
我是restapi新手,尝试使用tradierapi中的getquotes方法来检索特定公司的市场数据。请求将回复400,代码如下。以下是api文档的链接:https://documentation.tradier.com/brokerage-api/markets/get-quotes
try {
// MAKE REQUEST TO API
URL url = new URL("https://sandbox.tradier.com/v1/markets/quotes");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "Bearer <token>");
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/json");
connection.addRequestProperty("symbols", "AAPL");
connection.connect();
// GET INPUT STREAM RESPONSE FROM REQUEST
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));
// TAKING BITS AND BYTES FROM BUFFERED READER TO BUILD IT INTO A STRING OBJECT
StringBuilder json = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
json.append(line);
}
JSONObject obj = new JSONObject(json.toString());
System.out.println(obj);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
1条答案
按热度按时间6yoyoihd1#
(第1种方法)
将您的url更改为:--
"https://api.tradier.com/v1/markets/quotes?symbols=aapl,vxx190517p00016000&greenes=false“(我的意思是手动添加)
(第二种方法)
或者,
添加如下所示的requestparamcode:----
第三种方法