-
Notifications
You must be signed in to change notification settings - Fork 47
For use with SignalR Hub Client #18
Comments
Hi! I'm also stuck with the same problem. Any luck with that? |
I'm spend two hours for resolve this issue -_- . To fix that, you must see this post for getting cookies #14 Get it and add it to your HubConnection before calling CreateHubProxy Sample: _hubConnection.CookieContainer = cookies;
_hubProxy = _hubConnection.CreateHubProxy("coreHub");
// Start Connect
await _hubConnection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
Debug.WriteLine($"We have error when connecting to Bittrex Service Hub: {task.Exception?.GetBaseException()}");
return;
}
if (task.IsCompleted)
{
Debug.WriteLine("Connect to Bittrex Service Hub successfully.");
// Handle receive message from SignalR
_hubProxy.On("updateExchangeState", marketJSon => HandleUpdatedExchangeState(marketJSon));
}
}); |
Hi @raymondle Could you please provide full example, where you connect to the WS? :) |
@raymondle, would like to know as well. This example does not work (setting the agent header and cookie container):
|
@mhamburg I'm connect successfully because i'm clone this project and modified set User-Agent in file ClearanceHandler. As you see, why we add User-Agent to Headers of HubConnection and use same cookies but it not success? Because when you Start HubConnection, this SignalR Client will append private static void EnsureClientHeader(HttpRequestMessage request)
{
if (!request.Headers.UserAgent.Any())
request.Headers.TryAddWithoutValidation("User-Agent", "SignalR.Client.NET45/2.2.2.0 (Microsoft Windows NT 6.2.9200.0)");
} And remember dont try add User-Agent to your HubConnection. |
@raymondle Thx! (it is now working properly) You do not need to make changes to this library:
Just add the header before using the ClearanceHandler. (I used the .net standard header since it is different from the .net45 header) |
Thanks for the help @raymondle, i got it working as well. The User-Agent string the SignalR client uses gets generated here, so you can derive what you need: |
@mhamburg @raymondle I'm still getting 503. Could you please share your code, where you connect to SignalR server? |
@tompetko Could you please post your code snippet? Only part that was wrong in my code snippet was setting the wrong User-Agent header |
Thanks @mhamburg but I finally managed to get it working.
|
@mhamburg I realized, that this works only for connecting to websocket server. When I try to subscribe, 503 is returned. Have to try subscribing? |
@tompetko yep, i'm having same issue with you. Because when subscribe to market, it call request without User-Agent so that why we can't subscribe :(. I'm trying clone source and modify SignalR.Client Library https://github.com/SignalR/SignalR |
@raymondle I don't believe it's caused by absence of User-Agent header value. You can wrap |
I've been trying to debug this exact problem. Haven't found a solution yet, but I know whats different between the SignalR .NET client and what Chrome is doing. When using SignalR from .NET it seems to send the I'm not sure what part of the Here's my packet dump that shows SSE is being used: WSS.pdf |
Seems like it's going wrong in the WSS upgrade request: SignalR from .NET GET /signalr/connect?clientProtocol=1.4&transport=webSockets&connectionData=[%7B%22Name%22:%22corehub%22%7D]&connectionToken=HIZWRIqEQZGF7BwQ6IQlel9NPRAsNpxGbcOkIWxz6WY9HBekGplLSckie7Mo9jF9ZXY3cx9MVMB5tYjulT0knUwo1FliTaPyOgvkgtKso3wz3hCH HTTP/1.1
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Key: Glg5CpMPLQ4B5/5Zsl7tYg==
Sec-WebSocket-Version: 13
Host: socket.bittrex.com
Cookie: __cfduid=dd99c1bf6193752e41551572f5b330b621510612521; cf_clearance=c54d2ebf1bea6fd3117a9afa8c1be2bc1e219697-1510612526-10800 Response: HTTP/1.1 503 Service Temporarily Unavailable Browser GET wss://socket.bittrex.com/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=EkVK%2FdDXCiHFqxMv4KnKEhNkw%2FSaGO86LtT8ax26NZq7Ez23E6s%2FAS5sQAce0uSUmw%2BNXkQg95%2FYzaW3pz7e%2BYHjVUjfrsOO3%2FCeaIXkn05gfwu%2F&connectionData=%5B%7B%22name%22%3A%22corehub%22%7D%5D&tid=2 HTTP/1.1
Host: socket.bittrex.com
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: https://bittrex.com
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8,nl;q=0.6,af;q=0.4
Cookie: __cfduid=d7053452b970221dda141e228815ff6171507369717; .AspNet.ApplicationCookie=UzgOhOvot5wbNZOcSq68pZzVbUcIw0EwzirWT0a9HWifSht1RZ1sc7dFFXi5KIpN7d2DxAD7Lwe5wKlZdhdyE1lVPEHiF-ukrtxEshe0U0MuEKgpqOCLWMZj2KSerPBmX7WptREs2tWku2DW1jJJPhL96KNrYdPuJ3oTRqn0KgLwOmfZsIt8x9m-hzbEQXMEo2LVjHFpnUgzvDhlZTzr24BHIE_ItAeanO7w4XhkltKQxp-HyBRMahpx-xmaVuRaismjdN3NI8hcjWQXM918fMmz0mspF0KJJyn8BoOQF0EIVYWdflpCPOkv5W2VJ6P8VwkdN1fmOWT10eNFWqacm5OY87pg9S9DwW1KO3Gea1zEljei3l7WaWN91-1oOY-_2zYjOdAb_6mfKeWBzPvoBbkcpd-hZIfhz12Wckw9SFYZeMuX-1N6GBavC8nXVkeNjRNgIFxnt2Jya_ciuaXVFBmag90; cf_clearance=4ff47da9e02631b7272dff29983d42a19b2eb1b9-1510612725-10800
Sec-WebSocket-Key: Ik7JJDVOM2J7jPyqvkEmdQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Response HTTP/1.1 101 Switching Protocols Might be the User-Agent? Related issue: SignalR/SignalR#2058 |
I could never get the default client to work using .net core. So I found a way to do it using a package forked from Coinigy. I used the purewebsocket and modified it to use headers after I got blocked from yesterday. Then I ran my wpf code and the user agent is unable to be set. So I then used runtime directives to do what I could. It is fully functional, however the nuget reference is in the folder as debug. Getting a strange problem with one of 3 wpf apps not finding .net HTTP. I have tested it in both .net framework and .net core. Net core minimum is 2.0 and framework is 4.7 . The repositories are located at pcartwright81/PureWebSockets and pcartwright81/PureSignalRClient. |
.NET core support got me spending some time hunting for solutions too. But I believe it won't work because of this: https://github.com/SignalR/SignalR/blob/7d4e196653821ef5f26ef4e8b97f6a6eea3fe256/src/Microsoft.AspNet.SignalR.Client/Transports/AutoTransport.cs#L31-L33 I'll give the PureWebSocket a try later. Thanks! |
@Grepsy did you try passing in your own new WebSocketTransport to force the hubconnection to use WebSockets and never use SSE? I've tried the following but I get the same result as you're seeing:
|
This problem at ClientWebSocket, they are not support add User-Agent to Headers so that why we can't subscribe or using WebSocketTransport. |
@raymondle You're right. I've overriden a lot of WebSocket related classes of SignalR library just to allow setting of |
I have a (temporary) fix using the reverse-proxy Fiddler script to supply the if (oSession.url.Contains("/signalr/connect?")) {
oSession.oRequest.headers.Add("User-Agent", "SignalR.Client.NET45/2.2.2.0 (Microsoft Windows NT 6.2.9200.0)");
} I've anyone finds a more elegant solution I'd be happy to hear about it. |
Try using this websocket-sharp support custom headers at https://github.com/felixhao28/websocket-sharp. I had successfully for SubscribeToExchangeDeltas to Bittrex 😄 |
Hi @raymondle can I ask you for piece of code? :) I'm getting |
@tompetko i would love to see an example of your altered signalR client library, as it would be the desired solution (connect & SUBSCRIBE) for my existing .NET project which utilizes that lib (see OP). Thanks guys! |
Hi @junkomatic @raymondle ! This is my promised solution. https://github.com/tompetko/SignalR.WebSocketSharpTransport. Feel free to create pull requests. |
works/runs for me! it looks like the signalR client lib is intact and you added a wrapper from WebSockeSharp-customheaders lib, in addition to the Cloudflare scrape utility. nice work! |
@junkomatic You're really welcome! Anyway, I didn't manage to create unit tests for this solution, so any contribution would be appreciated :) So don't hesitiate to create pull requests guys! |
I just finished integrating this into my project, and it totally works. Man, I was sad before, but now I am so HAPPY! |
Wow! Thank @tompetko 👍 ❤️ |
Thanks. It seems Bittrex killed "updateSummaryState" 👎 Edit: looking at the source log from the referenced issue, "updateSummaryState" works if you're using "https://socket-stage.bittrex.com" as socket feed Uri. |
that does not work for me either. requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://socket-stage.bittrex.com/negotiate?connectionData=%5B%7B%22name%22%3A+%22coreHub%22%7D%5D&clientProtocol=1.5 |
In the demo, leave the bittrexUri as it is. Just change the bittrexFeedUri. |
using python, so probably different? |
Ah. Yes, I was talking about this repo, which is c#. To mimic what this does in python, probably you need to make a simple HTTP get request to "https://www.bittrex.com". Get the returned headers and cookies from that request and open the feed to the "socket-stage" uri, using those headers / cookies. By simple I mean using the cloudflare package, of course. |
Hi guys. I made an update to https://github.com/tompetko/SignalR.WebSocketSharpTransport so |
Great, thanks. |
gah cant get it to work for python yet |
@p0nt can you |
I created an issue at SignalR .NET Core repository, and they confirmed a new version (still in alpha) does support custom headers. So it seems like the simplest solution would be just to use a new SignalR. |
I'm trying to build a simple proof-of-concept with a .NET Core version of SignalR. Here's what I've got so far:
Theoretically it looks like it should work (at least you can specify custom headers) but currently I get an error "System.FormatException: No transports returned in negotiation response." I might've configured it wrong (i. e. I'm not sure if I've specified a correct feedUrl). Would love if anyone joined me on this one. P. S. To make it build you need a nightly build of Microsoft.AspNetCore.SignalR.Client from https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json |
It turned out .NET Core SignalR client dues not support old SignalR server... I expected them to implement the same SignalR protocol but it doesn't seem to be the case. |
Old SignalR itself does support .NET Core, so WebSocket-Sharp is the only problem. There project seems to be dead, but there's a PR with .NET Core support over here: sta/websocket-sharp#299 |
I gave up implementing .NET Core support for now. Will report my conclusions in case anyone needs it. The old SignalR itself does support .NET Core but it doesn't support custom headers. To send custom headers we integrated SignalR with websocket-sharp. Unfortunately this library's maintainer is a little weird and he did not merge custom headers support for websocket-sharp. So it exists only in a fork. What makes it worse, websocket-sharp is not actively maintained anymore, so it doesn't support .NET Core. There is a pull-request that implements .NET Core support for websocket-sharp. So basically, to make the solution above work on .NET Core we need to take a custom-header's fork, merge .NET Core support pull-request to it and then hope there're no critical bugs as both the fork and PR are quite outdated... |
I hacked together a .NET Core client using CloudFlareUtilities to pass Cloudflare clearance. I, however, noticed (and am trying to figure out why) that even after obtaining the clearance cookie any subsequent requests fail clearance again. My process is basically as follows:
Now, I'd expect that in step 2 the clearance cookie obtained in step 1 would still be valid but that isn't so. The request fails clearance and has to take a new challenge. I have spent days on this now but cannot figure it out. Anyone else has any input on this? I looked into node.bittrex.api and there any subsequent http requests pass clearance after excuting step 1 without any problems. |
Right - I can finally answer my own question thanks to this thread. Basically I have set a different User-Agent on requests subsequent to Step 1 above. As you can see in Step 1 no User-Agent is being specified so it defaults to the one set by the ClearanceHandler in EnsureClientHeader. In subsequent requests I set a User-Agent which is different from the one in the very first request. I suppose that CloudFlare will always validate the cookies against the User-Agent also (maybe it is being used as a salt when generating the cfuid or clearance cookies) and hence my requests where always rechallenged. Hope this helps someone else, too! |
Hi @emsfeld. What SignalR client do you use? |
Hi @tompetko I hacked together my own client as the .NET Core one only supports the latest server version as @siberianguy noted as well. |
I am unable to get this to work with my signalR hub client, trying to bypass the cloudflare recently implemented over bittrex.com websocket endpoints. I attach the _cfduid and cf_clearance cookies, and also use the same User-Agent header on my hubConnection obj, but i still get blocked with 503 status:
`
var handler = new ClearanceHandler();
var client = new HttpClient(handler);
var hubConnection = new HubConnection("https://www.bittrex.com/");
The text was updated successfully, but these errors were encountered: