soernt / signalr_client

A Flutter SignalR Client for ASP.NET Core
MIT License
129 stars 202 forks source link

Cannot start() connection to signalR server #9

Closed davbaron closed 5 years ago

davbaron commented 5 years ago

Hello, much like others, I cannot seem to start() a connection to the signalR server. I get back the dreaded Response Content-Type not supported: [application/json; charset=UTF-8]

I looked at the code in dartio_http_client.dart and do not understand some things, specifically with block lines 85 thru 97:

final contentTypeHeader = httpResp.headers["Content-Type"];
final isJsonContent =
    contentTypeHeader.indexOf("application/json") != -1;
if (isJsonContent) {
  content = await httpResp.transform(utf8.decoder).join();
} else {
  content = await httpResp.transform(utf8.decoder).join();
  // When using SSE and the uri has an 'id' query parameter the response is not evaluated, otherwise it is an error.
  if (isStringEmpty(uri.queryParameters['id'])) {
    throw ArgumentError(
        "Response Content-Type not supported: $contentTypeHeader");
  }
}

From what I can tell, the contentTypeHeader variable holds a 'growable list', not a simple string. Thus, when trying to find the 'indexOf("application/json")' if fails (returns -1) instead of returning 0 for the start of the 1st (0th) element in that list. In other words isJsonContent should be TRUE. image

What's future interesting is that as it stands right now, with a FALSE value, the content is still decoded properly and seems fine. However because there is no 'id' query param in the uri, the code throws the ArgumentError that several of us have hit.

So, what is the solution to this? Is this something that can be fixed?

Thank you,

-David

davbaron commented 5 years ago

Uh oh... I just found an item in StackOverflow: https://stackoverflow.com/questions/50980262/how-to-use-signalr-on-flutter

The comment by the Soernt, and the comment after his, seems to imply that this plug in will ONLY work with .Net Core. I am using a .Net frameworks/OWIN site. Does that really mean me (and others like me) cannot use this plug in? In re-reading the README on this repo, it does in fact 'only' say .Net Core.

soernt commented 5 years ago

Yes this library is only for .Net Core since Microsoft changed the protocol with .Net Core.

Kind regards, Sörnt

davbaron commented 5 years ago

Thank you for the verification Sörnt. I am now in the process of re-writing (porting) my .net framework web api site to .net core 2.2... hopefully it will not be too much effort and your plug in will then work.