cURL
You can use cURL from the terminal to make an HTTP request to the Ingest API. The following example posts a single JSON message to the source and displays the response headers.
curl \
-H "Content-Type: application/json" \
-H "Authorization: token 7836e0e6-2937-4ff9-9463-eff988e02de2" \
-X POST -d '{"testing":"123"}' \
-i \
https://listener-ingest-services-demo.io/message
Java
You can use Java to make an HTTP request to the Ingest API. The following example uses the HttpClient package to create a POST request that sends a single JSON message to the source and prints the response object.
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
public class HTTPSPostTest {
private void post(String urlStr, String token, String reqBody) throws Exception {
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "token " + token);
conn.setDoOutput(true);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(conn.getOutputStream());
outputStreamWriter.write(reqBody);
outputStreamWriter.flush();
int responseCode = conn.getResponseCode();
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder resp = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
resp.append(inputLine);
}
in.close();
System.out.println(resp.toString());
}
public static void main(String[] args) {
HTTPSPostTest https = new HTTPSPostTest();
String url = "https://listener-ingest-services-demo.io/message";
String token = "7836e0e6-2937-4ff9-9463-eff988e02de2";
String reqBody = "{\"testing\": \"123\"}";
try {
https.post(url, token, reqBody);
} catch (Exception e) {
e.printStackTrace()
}
}
Python
You can use Python to make an HTTP request to the Ingest API. The following example uses the requests package to create a POST request that sends a single JSON message to the source and prints the response object.
import urllib3
http = urllib3.PoolManager()
r = http.urlopen('POST', 'https://listener-ingest-services-demo.io/message',
headers={"Authorization": "token c79cd52e-607c-4fea-9da8-9dc1e5a60655"},
body='''{"testing": "123"}'''
)
print ("Response code: %s" % r.status)