Giter Site home page Giter Site logo

Comments (7)

milodude avatar milodude commented on May 29, 2024 2

The XMLHttpRequest error is due to Cors policy issue. I managed to solve it by doing the next steps in a C# application.

1- Define in your startup.cs file a new porperty ie:
readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

2-At your configure method in the same Startup.cs file add the next line to add Cors
services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, policy => { policy.WithOrigins("http://localhost:58944") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); });
Where WithOrigins must be filled with the UI host url you are trying to send the message from.

3- Use Cors at your Configure method in the same Startup.cs file
app.UseCors(MyAllowSpecificOrigins); app.UseRouting();
It must be defined before UseRouting method.

Please give it a shot and let everyone know if this worked out for you.

from signalr_core.

AdrianKlm avatar AdrianKlm commented on May 29, 2024 1

I have the same problem. Any information on when it will be fixed?

from signalr_core.

agwanyaseen avatar agwanyaseen commented on May 29, 2024 1

Same issue, these plugin not working on flutter web , Any Idea till when it will going to be fixed?

from signalr_core.

Codzaa avatar Codzaa commented on May 29, 2024 1

@jamiewest Hi !

I bumped into this same error but I found a different solution that does not involve configuring 'CORS'.

final connection = HubConnectionBuilder() .withUrl( 'http://localhost:9670/hub', HttpConnectionOptions( skipNegotiation: true, transport: HttpTransportType.webSockets, logging: (level, message) => print(message), )) .build();

You can simply set skipNegotiation to true, but when reading the docs on the microsoft site (https://docs.microsoft.com/en-us/javascript/api/%40aspnet/signalr/ihttpconnectionoptions?view=signalr-js-latest#skipnegotiation) , it says that you have to be using Web Sockets for this to work.

By the way what are the downsides to setting skipNegotiation to true, any security issues or something?

Environment
Flutter 2.8.0
.Net 5

from signalr_core.

Jddl avatar Jddl commented on May 29, 2024
            services.AddCors(op =>
            {
                op.AddPolicy("SignalRCors", set =>
                {
                    set.SetIsOriginAllowed(origin => true)
                       .AllowAnyHeader()
                       .AllowAnyMethod()
                       .AllowCredentials();
                });
            });

from signalr_core.

laimonas avatar laimonas commented on May 29, 2024

@AmbujaAK maybe try to look there
#24 (comment)

from signalr_core.

petsve avatar petsve commented on May 29, 2024

Allowing Cors solved it for me too. But the port could change between runs so I made the server code a bit more generic.
In .NET you could use the following:

services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => builder.SetIsOriginAllowed(origin => new Uri(origin).IsLoopback) ); });

from signalr_core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.