Advertisement
dereksir

Untitled

Oct 18th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 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.         // Set custom User Agent
  12.         string customUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36";
  13.         httpClient.DefaultRequestHeaders.Add("User-Agent", customUserAgent);
  14.  
  15.         // Make a GET request to httpbin.io/user-agent
  16.         HttpResponseMessage response = await httpClient.GetAsync("https://httpbin.io/user-agent");
  17.  
  18.         // Read and print the content
  19.         string content = await response.Content.ReadAsStringAsync();
  20.         Console.WriteLine(content);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement