-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetHttpsFbDb.go
More file actions
48 lines (41 loc) · 1.51 KB
/
Copy pathgetHttpsFbDb.go
File metadata and controls
48 lines (41 loc) · 1.51 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func main() {
url := "https://www.footballdb.com/scores/index.html?lg=NFL&yr=2024&type=reg&wk=1"
// Create a custom HTTP client
client := &http.Client{}
// Create a new request
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatalf("Failed to create request: %v", err)
}
// Add headers (e.g., User-Agent)
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; MyGolangBot/1.0)")
// Make the request
resp, err := client.Do(req)
if err != nil {
log.Fatalf("Failed to make request: %v", err)
}
defer resp.Body.Close()
// Check the status code
if resp.StatusCode == http.StatusForbidden {
fmt.Printf("Received 403 Forbidden. Headers sent: %v\n", req.Header)
fmt.Printf("Response headers: %v\n", resp.Header)
body, _ := io.ReadAll(resp.Body) // Read body for more details
fmt.Printf("Response body: %s\n", string(body))
return
} else if resp.StatusCode != http.StatusOK {
log.Fatalf("Unexpected status code: %d", resp.StatusCode)
}
// Read and print the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Failed to read response body: %v", err)
}
fmt.Println("Response:", string(body))
}