Skip to content

Instantly share code, notes, and snippets.

@pm-kartik-sura
Created May 26, 2015 11:36
Show Gist options
  • Select an option

  • Save pm-kartik-sura/4bbbd70dec915519084c to your computer and use it in GitHub Desktop.

Select an option

Save pm-kartik-sura/4bbbd70dec915519084c to your computer and use it in GitHub Desktop.
HTTP request
// HTTPRequester project main.go
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
func CallHTTP(url string) error {
req, err := http.NewRequest("GET", url, nil)
// req.Header.Add("User-Agent", r.UserAgent())
req.ParseForm()
timeout := time.Duration(time.Duration(1000) * time.Millisecond)
client := http.Client{
Timeout: timeout,
}
response, err := client.Do(req)
if err != nil {
log.Println(err)
return err
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Println(err)
return err
}
fmt.Println("response contents: ", string(contents))
return nil
}
func main() {
CallHTTP("http://www.google.com")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment