1 回答

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
有點(diǎn)不清楚你想做什么。在文中,您說您正在嘗試使用 HTTP 事件收集器 (HEC) 發(fā)送數(shù)據(jù)。但是,示例代碼看起來正在嘗試執(zhí)行搜索。
要將數(shù)據(jù)發(fā)送到 Java 中的 HEC 端點(diǎn),以下代碼片段可能是合適的起點(diǎn)。
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://<SERVER>:8088/services/collector/event");
httppost.addHeader("Authorization", " Splunk <token id>");
String eventStr = "{sourcetype=_json, index=main, event={ <JSON> }}"
httppost.setEntity(new StringEntity(eventStr);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("response: " + entity);
添加回答
舉報(bào)