Note: this API needs to be updated to v2. Identify is now a resource on the Language Translation API.
Making an HTTP REST API POST request in Java is in principle as simple this:
Request request = Request.Post(serviceURI)
Executor executor = Executor.newInstance();
String response = executor.execute(request).returnContent().asString();
This code, uses the Apache Fluent API, which exposes only the essentials of the Apache HTTPClient.
The Authorization header is required for authentication by the Watson API, and is a base64 encoded string.
String auth = username + ":" + password;
String basicAuthorization = "Basic "+ Base64.encodeBase64String(auth.getBytes());
The POST request is “x-www-form-urlencoded” and in Java consists of a List<NameValuePair>:
List<NameValuePair> params = new ArrayList<NameValuePair>();