How to send HTTP request in java? [duplicate]

You can use java.net.HttpUrlConnection. Example (from here), with improvements. Included in case of link rot: public static String executePost(String targetURL, String urlParameters) { HttpURLConnection connection = null; try { //Create connection URL url = new URL(targetURL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(“POST”); connection.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”); connection.setRequestProperty(“Content-Length”, Integer.toString(urlParameters.getBytes().length)); connection.setRequestProperty(“Content-Language”, “en-US”); connection.setUseCaches(false); connection.setDoOutput(true); //Send request DataOutputStream wr = new … Read more

How to send HTTP request in java?

You can use java.net.HttpUrlConnection. Example (from here), with improvements. Included in case of link rot: public static String executePost(String targetURL, String urlParameters) { HttpURLConnection connection = null; try { //Create connection URL url = new URL(targetURL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(“POST”); connection.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”); connection.setRequestProperty(“Content-Length”, Integer.toString(urlParameters.getBytes().length)); connection.setRequestProperty(“Content-Language”, “en-US”); connection.setUseCaches(false); connection.setDoOutput(true); //Send request DataOutputStream wr = new … Read more