任务<string>不包含GetAwaiter()的定义

时间:2017-05-10 12:58:58

标签: c#

我正在尝试验证URL凭据,但我收到此错误:

  

任务不包含&#39; GetAwaiter&#39;

的定义
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();
}

enter image description here

0 个答案:

没有答案