Sure using it as a API to Java. Here is the client side
public String sendMessage(String question, String user) throws
UnknownHostException, IOException, ClassNotFoundException,
InterruptedException{
String url = "http://localhost:8093";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add reqest header
con.setRequestMethod("POST");
con.setRequestProperty("content-type", "text/plain");
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
//String body = "{user:user1,question:gh threw the ball}";
String body = question;
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(body);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
//System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
System.out.println("response:" + response);
String result = response.toString();
if(result.contains(".")) {
result = result.replace(".", "");
}
result = result.trim();
return response.toString();
}
--
You received this message because you are subscribed to the Google Groups
"opencog" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/opencog.
To view this discussion on the web visit
https://groups.google.com/d/msgid/opencog/6cf4e8ce-9c68-4206-8876-d902f65e4f6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.