[C#] 纯文本查看 复制代码
_logger.LogInformation("Checking QR code status...");
do
{
await Task.Delay(800);
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var statusResponse = await client.GetStringAsync($"{BaseUrl}/qrCode/getStatus.htl?ts={timestamp}&uuid={uuid}");
if (!int.TryParse(statusResponse, out statusCode))
{
_logger.LogError("Failed to parse status code. As the Response is {statusResponse}", statusResponse);
}
switch (statusCode)
{
case 3:
_logger.LogWarning("QR code expired.");
break;
case 2:
_logger.LogInformation("QR code scanned.");
break;
}
} while (statusCode != 1);
_logger.LogInformation("QR code login successful.");
await PostLoginAsync(uuid, executionValue);
Cookie ticketCookie = CookieContainer.GetAllCookies()
.FirstOrDefault(c => c.Name == "MOD_AUTH_CAS")
?? throw new Exception("Failed to get ticket cookie.");
string ticket = ticketCookie.Value
.AsSpan(9).ToString();
await client.GetAsync($"{PortalUrl}/index.do?ticket={ticket}");
_ = cookieContainer.GetAllCookies().First(c => c.Name == "_WEU");
return true;
我设计了上方代码以实现校园网 cookie 的获取,但实际上该代码在登录成功后会经历两次重定向,而我在写的时候发现始终无法获得重定向的信息,httpclient 也不能获取到我所需的cookie(即使在默认 redirect=true 的情况下)。这样的情况究竟是什么原因造成的? |