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 :: implement the bubble sort algorithm on the following arraylist 
Java :: java string to float 
Java :: java secretkey 
Java :: fhow to find location of java jdk 
Java :: java comments 
Java :: date format in java 
Java :: java remove last character 
Java :: spring boot save file to static folder 
Java :: java loop through list 
Java :: Duration class java 
Java :: main method 
Java :: for each loop java 
Java :: okhttp post 
Java :: arraylist to int array conversion in java 
Java :: java arraylist declaration 
Java :: java append file 
Java :: iterate thrpugh hasmap 
Java :: native insert query in jpa repository 
Java :: how to run individual test in java maven 
Java :: java sum of array elements 
Java :: java.lang.string cannot be cast to java.lang.double react native 
Java :: how to take max value from priority queue in java 
Java :: java wait(timeout) 
Java :: convert two bytes to int java 
Java :: java create new object 
Java :: java fahrenheit to celsius 
Java :: android canvas line thickness 
Java :: how to substring in java 
Java :: java stop script 
Java :: pre increment and post increments java 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =