fork download
  1. using System;
  2. using System.Net.Http;
  3. using System.Net.Http.Headers;
  4. using System.Threading.Tasks;
  5.  
  6. class Program
  7. {
  8. static async Task Main(string[] args)
  9. {
  10. // Define the base URL of the REST API
  11. string baseUrl = "https://a...content-available-to-author-only...s.com/developer/api/";
  12.  
  13. // Define the bearer token
  14. string bearerToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTAyMzQwNjIsImV4cCI6MjAyNTU5NDA2MiwidG9rZW5fdHlwZSI6ImRldmVsb3Blcl9hY2Nlc3MiLCJmaXJzdF9uYW1lIjoiVmlzaGFsIiwibGFzdF9uYW1lIjoiU2F4ZW5hIiwib2NjdXBhdGlvbiI6Ik90aGVyIiwidXNlcl9jb21wYW55IjoiQXRraW5zIiwidXNlcl9lbWFpbCI6InZpc2hhbC5zYXhlbmFAYXRraW5zZ2xvYmFsLmNvbSJ9.C-C0xrce2yQj4SHB083wtYElvNQj9b_Q5nvGhtXbTwI";
  15.  
  16. // Create an instance of HttpClient
  17. using (HttpClient client = new HttpClient())
  18. {
  19. // Set the base address of the API
  20. client.BaseAddress = new Uri(baseUrl);
  21.  
  22. // Add bearer token to the request headers
  23. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
  24.  
  25. try
  26. {
  27. // Send a GET request to the API endpoint
  28. HttpResponseMessage response = await client.GetAsync("getapitoken/");
  29.  
  30. // Check if the request was successful
  31. if (response.IsSuccessStatusCode)
  32. {
  33. // Read the response content as a string
  34. string responseData = await response.Content.ReadAsStringAsync();
  35.  
  36. // Print the response data
  37. Console.WriteLine(responseData);
  38. }
  39. else
  40. {
  41. // Print error message if request was not successful
  42. Console.WriteLine($"Failed to retrieve data. Status code: {response.StatusCode}");
  43. }
  44. }
  45. catch (HttpRequestException e)
  46. {
  47. // Print any exceptions that occur during the request
  48. Console.WriteLine($"Request failed: {e.Message}");
  49. }
  50. }
  51. }
  52. }
  53.  
Success #stdin #stdout 0.17s 40812KB
stdin
Standard input is empty
stdout
Request failed: Resource temporarily unavailable (app.2050-materials.com:443)