我有一个在CodedUITest类中的TestMethod,它使用HttpClient从本地服务器获取数据。
[TestMethod]
public void CodedUITestMethod()
{
string ServiceURI = "http://localhost:34562/GetTestResult";
HttpClient httpClient = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, ServiceURI);
HttpResponseMessage response = httpClient.SendAsync(request).Result;
}
然而,在最后一行总是会抛出异常,例如:
{System.UnauthorizedAccessException: Use of networking APIs requires the ID_CAP_NETWORKING capability to be defined in the application manifest.
at MS.Internal.Modern.ClientHttpWebRequestCreator.Create(Uri uri)
at System.Net.WebRequest.Create(Uri requestUri, Boolean schemeOnly)
at System.Net.WebRequest.Create(Uri requestUri)
at System.Net.Http.HttpClientHandler.CreateAndPrepareWebRequest(HttpRequestMessage request)
at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)}
根据所需清单功能,似乎没有办法为Coded UI项目指定应用程序清单。
有人知道如何指定ID_CAP_NETWORKING功能吗?