Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net.Http;
- class Program
- {
- static async Task Main()
- {
- // Create an instance of HttpClient
- HttpClient httpClient = new HttpClient();
- // Define your User Agent List
- List<string> userAgents = new List<string>
- {
- "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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
- };
- // Generate a random index
- var random = new Random();
- int randomIndex = random.Next(userAgents.Count);
- // Select a random UA using the randomIndex
- string randomUserAgent = userAgents[randomIndex];
- // Set selected User Agent
- httpClient.DefaultRequestHeaders.Add("User-Agent", randomUserAgent);
- // Make a GET request to httpbin.io/user-agent
- HttpResponseMessage response = await httpClient.GetAsync("https://httpbin.io/user-agent");
- // Read and print the content
- string content = await response.Content.ReadAsStringAsync();
- Console.WriteLine(content);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement