Projet_POO/Projet_POO/src/servlet/Post.java
2021-01-12 10:39:07 +01:00

37 lines
1,009 B
Java

package servlet;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class Post {
private static final String POST_URL = liste.ConstanteListeUtilisateur.URL_SERVLET;
public static void sendPOST(String msg) throws IOException { // Publish cmd : change$$$id$$$nom$$$ip$$$dedans$$$statut
URL obj = new URL(POST_URL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
// Output Stream
con.setDoOutput(true);
DataOutputStream os = new DataOutputStream(con.getOutputStream());
//os.write(POST_PARAMS.getBytes());
os.writeBytes(msg);
os.flush();
os.close();
// For POST only - END
int responseCode = con.getResponseCode();
System.out.println("POST Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { //success
System.out.println("Post success");
} else {
System.out.println("POST request not worked");
}
}
}