import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
I need to do the same in golang
i.e read and print the html source code, but cannot find the relation between two, I am a beginner with Go language, thank you in advance
Hope this will help:
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func Error(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
response, err := http.Get("http://www.oracle.com/")
Error(err)
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
Error(err)
fmt.Printf("%s
", contents)
}
For more details: https://golang.org/pkg/net/http/