SignalR Hub客户端 - 使用ClearanceDelegate绕过cloudflare

时间:2017-09-11 00:55:16

标签: .net http-headers signalr cloudflare

我试图绕过最近在Bittrex.com signalR集线器端点上实现的cloudflare检查。

我正在使用此实用程序创建ClearenceDelegate:https://github.com/elcattivo/CloudFlareUtilities

这适用于我的常规HttpRequestMessages,但我正在尝试让我的集线器连接。

我已经附加了_cfduid和cf_clearance cookie,并且还添加了与初始请求相同的User-Agent标头,但是我仍然无法连接它...我得到了相同的503,好像我什么都没做。< / p>

是否有办法强制hubConnection obj使用初始的HttpClient或处理程序?

        var handler = new ClearanceHandler();
        var client = new HttpClient(handler);
        var hubConnection = new HubConnection("https://www.bittrex.com/");

        try
        {

            HttpRequestMessage msg = new HttpRequestMessage()
            {
                RequestUri = new Uri("https://www.bittrex.com/"),
                Method = HttpMethod.Get
            };


            HttpResponseMessage response = await client.SendAsync(msg);
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("SUCCESS");
            }



            IEnumerable<string> heads;
            if (msg.Headers.TryGetValues("User-Agent", out heads))
            {
                foreach (string s in heads)
                {
                    Console.WriteLine(s);
                    //Outputs: "Client/1.0"

                    //Add User-Agent header to hubConnection
                    hubConnection.Headers.Add("User-Agent", s);
                }
            }


            hubConnection.CookieContainer = new CookieContainer();
            IEnumerable<string> cookies;

            //set the "_cfduid" and "cf_clearance" cookies we recieved on the hubConnection
            if (response.Headers.TryGetValues("set-cookie", out cookies))
            {
                foreach (var c in cookies)
                {
                    Uri target = new Uri("https://www.bittrex.com/");
                    hubConnection.CookieContainer.SetCookies(target, c);
                }
            }


        }
        catch (AggregateException ex) when (ex.InnerException is CloudFlareClearanceException)
        {
            Console.WriteLine(ex.InnerException.Message);
        }


        Console.WriteLine("CONNECTING");




        //try to connect to the hub with attached cookies and user-agent header:
        await hubConnection.Start();

        btrexHubProxy.On<MarketDataUpdate>("updateExchangeState", update => 
        BtrexRobot.UpdateEnqueue(update));
        //btrexHubProxy.On<SummariesUpdate>("updateSummaryState", update =>  Console.WriteLine("FULL SUMMARY: "));
        btrexHubProxy = hubConnection.CreateHubProxy("coreHub");

0 个答案:

没有答案