37 lines
		
	
	
	
		
			1,006 B
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
	
		
			1,006 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 = "http://localhost:8080/Servlet_MBP/test";
 | |
| 	
 | |
| 	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");
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| }
 |