Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add headers to @aspnet/signalr Javascript client

I'm using @aspnet/signalr Official Javascript client from This npm package

I wondering if there is the way to add Header configuration to the client connection header

How I build the connection

let connection = new signalR.HubConnectionBuilder() .withUrl( "https://some.signalr-host.com" ) .build();

like image 437
Aphicha Intaragumhaeng Avatar asked Aug 24 '26 15:08

Aphicha Intaragumhaeng


1 Answers

The definition for IHttpConnectionOptions got a headers property in early 2020. (It's not visible on the documentation website, but is in the Typescript definition files.) You can now do as follows:

const connection = new signalR.HubConnectionBuilder()
  .withUrl("https://some.signalr-host.com", {
       headers: {"foo": "bar"}
   })
  .build();
like image 98
Arithmomaniac Avatar answered Aug 27 '26 14:08

Arithmomaniac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!