Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- // import the necessary dependencies
- import (
- "fmt"
- "io"
- "net/http"
- "math/rand"
- )
- func main() {
- // list of User-Agent strings
- var userAgents = []string{
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
- // add more UA strings as needed
- }
- // select a random UA from the list
- randomIndex := rand.Intn(len(userAgents))
- randomUA := userAgents[randomIndex]
- // create custom HTTP client with custom Transport
- client := &http.Client{
- Transport: &http.Transport{},
- }
- // create HTTP request
- req, err := http.NewRequest("GET", "https://httpbin.io/user-agent", nil)
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
- // set User-Agent header
- req.Header.Set("User-Agent", randomUA)
- // make HTTP request
- response, err := client.Do(req)
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
- // close the response body
- defer response.Body.Close()
- // read the response body
- body, err := io.ReadAll(response.Body)
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
- // print the text content
- fmt.Println(string(body))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement