-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
31 lines (28 loc) · 788 Bytes
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"io"
"net/http"
"github.com/pkg/errors"
)
func HTTPGet(url string) ([]byte, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, errors.Wrap(err, "httpget")
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36")
req.Header.Set("Origin", "https://twitcasting.tv")
client := new(http.Client)
resp, err := client.Do(req)
if err != nil {
return nil, errors.Wrap(err, "httpget")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.Errorf("status code: %d", resp.StatusCode)
}
buf, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(err, "httpget")
}
return buf, nil
}