In this proyect that I’m actually worked out, but im still try to find out the problem which cannot allow go the information by the database (Im working in a Java Bean-Technology) and stills I dont know where is it exactily.
I received as a result error 500 in the output, obviously it dosen’t receive an upgrade from the database.
@ManagedBean
public class TestJSON {
private static URL url;
private static String sitio = "http://localhost:8088/";
public static int postJSON(Empresarios empresarios) throws
IOException{
url = new URL(sitio+"Empresarios/guardar");
HttpURLConnection http;
http = (HttpURLConnection)url.openConnection();
try {
http.setRequestMethod("POST");
}catch(ProtocolException e) {
e.printStackTrace();
}
http.setDoOutput(true);
http.setRequestProperty("Accept","application/json");
http.setRequestProperty("Content-Type", "application/json");
String data = "{"
+ ""codigo":""+empresarios.getCodigo()
+ "","arl":""+empresarios.getArl()
+ "","cargo":""+empresarios.getCargo()
+ "","dependencia":""+empresarios.getDependencia()
+ "","eps":""+empresarios.getEps()
+ "","fecha":""+empresarios.getFecha()
+ "","nombre":""+empresarios.getNombre()
+ "","pensiones":""+empresarios.getPensiones()
+ "","sueldo":""+empresarios.getSueldo()
+ ""}";
byte[] out = data.getBytes(StandardCharsets.UTF_8);
OutputStream stream = http.getOutputStream();
stream.write(out);
int respuesta = http.getResponseCode();
System.out.println(respuesta);
http.disconnect();
return respuesta;
}
}
´´´
New contributor
WWN27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.