This is my simple program (code inside the try catch block) that will be responsible to call a webservice running. Basically this is responsible to log the event of the application to a webService:
updated question code
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class NetClientPost {
HttpURLConnection conn = null;
NetClientPost() throws Exception {
URL url = new URL("http://localhost:8080/RestTest/custom/log_service");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
}
public static void main(String[] args) {
NetClientPost po;
try {
po = new NetClientPost();
po.execute();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void execute() {
try {
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
String input = "{\"qty\":100,\"name\":\"eee 4\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}