我正在尝试验证URL凭据,但我收到此错误:
任务不包含' GetAwaiter'
的定义
public class Methods
{
public static async Task<JObject> Get(string url, string username, string password)
{
var credentials = new NetworkCredential(username, password);
HttpClientHandler handler = new HttpClientHandler { Credentials = credentials };
HttpClient client = new HttpClient(handler);
// client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
return JObject.Parse(await response.Content.ReadAsStringAsync());
}
return new JObject { response.StatusCode };
}
}
public async Task<IActionResult> Index()
{
// Methods RestMethod = new Methods();
var httpClient = new HttpClient();
var data = await Methods.Get("http://www.myportal.com/api/now/table/core_company", "user@myportal.com", "Password123");
return View();
}