Well, i have this request in Postman:
127.0.0.1:8000/empleado/615050/retrieve-update/
and i add this body:
{"nombre":Marc}
this request working for me, in my API development in Django
but, when i try to replicate this request in my Java desktop app, fail and nothing happen. This is my Java code:
public void sendJson() {
JsonObjectBuilder o = Json.createObjectBuilder();
o.add("contrasenia", txtPass.getText());
JsonObject contra = o.build();
String contraS = contra.toString();
System.out.println(contraS);
try {
URL url = new URL("http://localhost:8000/empleado/" + txtUsuario.getText() + "/retrieve-update/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("PATCH");
conn.setRequestProperty("Content-Type","application/json;charset=UTF-8");
conn.setDoOutput(true);
conn.setDoInput(true);
OutputStream os = conn.getOutputStream();
os.write(contraS.getBytes(StandardCharsets.UTF_8));
os.close();
} catch (MalformedURLException malformedURLException) {
malformedURLException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
Ideas? thank, sorry for my English