39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package image
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// Make an HTTP Get Request to u
|
|
func GetHTTPResource(u string) (*http.Response, error) {
|
|
// Prepare HTTP Client, Cookie and Request
|
|
client := &http.Client {}
|
|
cookie := &http.Cookie {
|
|
Name : "POPUPCHECK",
|
|
Value : strconv.FormatInt(time.Now().UnixNano() / 1000000, 10),
|
|
Domain : "gronkh.de",
|
|
Path : "/",
|
|
}
|
|
req, err := http.NewRequest("GET", u, nil)
|
|
req.AddCookie(cookie)
|
|
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
|
req.Header.Add("Cache-Control", "max-age=0")
|
|
req.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12")
|
|
if err != nil {
|
|
log.Fatalf("FAT HTTP - Failed to create new Request: %+v", err)
|
|
return nil, err
|
|
}
|
|
// Execute HTTP Request
|
|
res, err := client.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if res.StatusCode == http.StatusNotFound {
|
|
return nil, nil
|
|
}
|
|
return res, nil
|
|
}
|