Example #1
0
        private static async void Page_Response(object sender, ResponseCreatedEventArgs e)
        {
            Log.Info($"Page_Response {e.Response.Request.Url}");
            if (e.Response.Request.Url.Contains("referer_frame"))
            {
                var body = await e.Response.TextAsync();

                //await e.Response.Request.RespondAsync(new ResponseData { Body = body });
            }
        }
        private async Task CaptureJsonResponseAsync <T>(
            RequestType requestType,
            ResponseCreatedEventArgs args,
            Func <string, T> deserialize)
        {
            await Task.Yield();

            var body = await args.Response.TextAsync();

            var requestId = $"{DateTimeOffset.UtcNow.Ticks:D20}-{Guid.NewGuid():N}";

            _queue.Enqueue(new Response(
                               requestId,
                               _operationType,
                               _operationParameters,
                               requestType,
                               DateTimeOffset.UtcNow,
                               args.Response.Request.Method,
                               args.Response.Request.Url,
                               body));

            try
            {
                AddDeserializedResponse(
                    requestId,
                    deserialize(body));
            }
            catch (JsonException)
            {
                try
                {
                    AddDeserializedResponse(
                        requestId,
                        _deserializer.ErrorResponse(body));

                    var prettyJson = JObject.Parse(body).ToString(Formatting.Indented);
                    _logger.LogError(
                        $"An error was returned by Kroger.com:{Environment.NewLine}{{ErrorJson}}",
                        prettyJson);
                }
                catch
                {
                    // Ignore these failures.
                }

                throw;
            }
        }
    private void Page_Response(object sender, ResponseCreatedEventArgs e)
    {
        if (DebugInfo)
        {
            Console.WriteLine($"Page_Response: {e.Response.Url}.{Environment.NewLine}Headers: {string.Join(Environment.NewLine, e.Response.Headers.Select(h => $"{h.Key}: {h.Value}"))}");
        }

        if (e.Response.Headers.ContainsKey(SetCookieHeader))
        {
            Uri    uri     = new Uri(e.Response.Url);
            string baseUrl = $"{uri.Scheme}://{uri.Host}";

            string cookies = e.Response.Headers["set-cookie"];

            if (DebugInfo)
            {
                Console.WriteLine($"Cookies: {cookies}");
            }

            string theCookie = cookies.Split('\n').FirstOrDefault(cookie => cookie.StartsWith(CloudflareClearanceKey));

            if (theCookie != null)
            {
                CookieContainer.SetCookies(new Uri(baseUrl), theCookie);
                Cookie cloudflareClearance = CookieContainer.GetCookies(new Uri(baseUrl)).FirstOrDefault(c => c.Name == CloudflareClearanceKey);

                if (cloudflareClearance != null)
                {
                    if (DebugInfo)
                    {
                        Console.WriteLine($"Cloudflare clearance cookie found: {cloudflareClearance.Value}");
                    }

                    OK = true;
                    CancellationTokenSource.Cancel();
                }
            }
        }
    }
Example #4
0
 private static async void Page_Response(object sender, ResponseCreatedEventArgs e)
 {
     Console.WriteLine(e.Response.Status);
 }