Advertisement
dereksir

Untitled

Oct 18th, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2. using System.Net.Http;
  3.  
  4. class Program
  5. {
  6.     static async Task Main()
  7.     {
  8.         // Create an instance of HttpClient
  9.         HttpClient httpClient = new HttpClient();
  10.  
  11.         // Define your User Agent List
  12.         List<string> userAgents = new List<string>
  13.         {
  14.  
  15.             "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",
  16.             "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
  17.             "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
  18.            
  19.         };
  20.  
  21.         // Generate a random index
  22.         var random = new Random();
  23.         int randomIndex = random.Next(userAgents.Count);
  24.         // Select a random UA using the randomIndex
  25.         string randomUserAgent = userAgents[randomIndex];
  26.        
  27.         // Set selected User Agent
  28.         httpClient.DefaultRequestHeaders.Add("User-Agent", randomUserAgent);
  29.  
  30.         // Make a GET request to httpbin.io/user-agent
  31.         HttpResponseMessage response = await httpClient.GetAsync("https://httpbin.io/user-agent");
  32.  
  33.         // Read and print the content
  34.         string content = await response.Content.ReadAsStringAsync();
  35.         Console.WriteLine(content);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement