I’m currently working on a script to get the response values from a cookie. The code below has the following error:
CS4033: The ‘await’ operator can only be used within an async method. Consider making this method with the ’async’ modifier and changing its return type to ‘Task’.
Can you please advise me what I’m missing in the code below? I’m using Visual Studio 2019. Thanks
using System;
namespace DummyConsole
{
public partial class Program
{
static void Main(string[] args)
{
GetCookie.CheckHeader();
}
}
}
// GetCookie Class
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace DummyConsole
{
public class GetCookie
{
public static void CheckHeader()
{
var myClientHandler = new HttpClientHandler();
myClientHandler.CookieContainer = new CookieContainer();
var client = new HttpClient(myClientHandler);
var response = await client.GetAsync("https://www.mydomain.com/"); // <-- He're where I get the error.
var cookieCollection = myClientHandler.CookieContainer.GetCookies(new Uri("https://www.mydomain.com/"));
foreach (var cookie in cookieCollection.Cast<Cookie>())
{
Console.WriteLine(cookie);
}
}
}
}