[英]How to get JSON data from solar winds Orion rest API using java
我想從solarwinds orion rest api 獲取JSON 數據,並且必須將這些JSON 數據寫入excel 文件中。
我假設您需要一個 Java 程序來向 API 端點發送 post 請求。 ApacheHTTP 庫來救援。 您可以從此處的文檔中閱讀更多內容。 官方 apache 網站中的更多信息
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://www.a-domain.com/foo/");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("param-1", "12345"));
params.add(new BasicNameValuePair("param-2", "Hello!"));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
// do something useful
}
}
取自這個答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.