Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

get request in java

import java.io.*;
import java.net.*;

public class c {

   public static String getHTML(String urlToRead) throws Exception {
      StringBuilder result = new StringBuilder();
      URL url = new URL(urlToRead);
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setRequestMethod("GET");
      try (BufferedReader reader = new BufferedReader(
                  new InputStreamReader(conn.getInputStream()))) {
          for (String line; (line = reader.readLine()) != null; ) {
              result.append(line);
          }
      }
      return result.toString();
   }

   public static void main(String[] args) throws Exception
   {
     System.out.println(getHTML(args[0]));
   }
}
Comment

PREVIOUS NEXT
Code Example
Java :: get text from a jtextfield 
Java :: android checkbox tint color 
Java :: toCharArray() method java 
Java :: android java xml combo box 
Java :: How to close jframe on click of button 
Java :: java main method 
Java :: string to hexstring In java 
Java :: java get year 
Java :: Exception in thread "main" java.util.zip.ZipException: error 
Java :: math library java 
Java :: upload converted base64 to image object to oss without saving in java 
Java :: how to add an image to a gui in java windowbuilder 
Java :: change image on button click android studio 
Java :: How to count the number of islands (groups of adjacent 1s) in a grid of 1s (land) and 0s (water), in Java? 
Java :: java scanner string nextline after nextint 
Java :: java list distinct by object attribute 
Java :: overloading + operator in java 
Java :: double to string java 
Java :: how to print an array in java 
Java :: activitycompat.requestpermissions not working 
Java :: springdoc 
Java :: How to find the next greater permutation of a list of numbers, in Java? 
Java :: java break 2 for loops 
Java :: compare two times in java 
Java :: switch case java with char 
Java :: set path in windows 
Java :: java convert date to localdate 
Java :: set source image in android studio 
Java :: how to create an array list in java 
Java :: change color of drawable android studio 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =