Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- namespace testhttpclient
- {
- class Program
- {
- static void Main(string[] args)
- {
- string result = MakeCall().Result;
- Console.WriteLine(result);
- Console.ReadLine();
- }
- public static async Task<string> MakeCall()
- {
- string result = String.Empty;
- HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://www.example.com/"); //"http://www.icanhazip.com/");
- using (HttpClient httpClient = new HttpClient())
- {
- using (HttpResponseMessage response = await httpClient.SendAsync(request))
- {
- if (response.IsSuccessStatusCode == true) // Takes approximately 22-23 seconds to reach this line
- {
- result = await response.Content.ReadAsStringAsync(); // Returns result quickly at this point
- }
- else
- {
- result = "Failure";
- }
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement