mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-19 21:03:11 -07:00
Replace HttpWebRequest with HttpClient (#1886)
HttpWebRequest is deprecated and it is trivial to ping using the replacement API.
This commit is contained in:
parent
f27bdba85a
commit
172a370722
1 changed files with 7 additions and 29 deletions
|
@ -18,6 +18,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace CalculatorUITestFramework
|
namespace CalculatorUITestFramework
|
||||||
|
@ -143,11 +144,11 @@ namespace CalculatorUITestFramework
|
||||||
|
|
||||||
private bool Ping()
|
private bool Ping()
|
||||||
{
|
{
|
||||||
bool pinged = false;
|
|
||||||
|
|
||||||
Uri status;
|
Uri status;
|
||||||
|
|
||||||
Uri service = this.ServiceUrl;
|
Uri service = this.ServiceUrl;
|
||||||
|
HttpClient httpClient = new HttpClient();
|
||||||
|
httpClient.Timeout = this.InitializationTimeout;
|
||||||
|
|
||||||
if (service.IsLoopback)
|
if (service.IsLoopback)
|
||||||
{
|
{
|
||||||
status = new Uri("http://localhost:" + Convert.ToString(this.Port) + "/status");
|
status = new Uri("http://localhost:" + Convert.ToString(this.Port) + "/status");
|
||||||
|
@ -156,32 +157,9 @@ namespace CalculatorUITestFramework
|
||||||
{
|
{
|
||||||
status = new Uri(service + "/status");
|
status = new Uri(service + "/status");
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime endTime = DateTime.Now.Add(this.InitializationTimeout);
|
var httpResponse = httpClient.GetAsync(status);
|
||||||
while (!pinged & DateTime.Now < endTime)
|
return httpResponse.Result.IsSuccessStatusCode;
|
||||||
{
|
|
||||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(status);
|
|
||||||
HttpWebResponse response = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (response = (HttpWebResponse)request.GetResponse())
|
|
||||||
{
|
|
||||||
pinged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
pinged = false;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (response != null)
|
|
||||||
{
|
|
||||||
response.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pinged;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue