title: SignalR in Swift using SwiftR - Error During Negotiation Request
body: <p>I'm using .netcore with VS community edition on my Mac and would like to use SignalR for an iOS app using SwiftR</p>
  
  <p>I got a working project directly from here:
  <a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-2.1&amp;tabs=visual-studio-mac" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-2.1&amp;tabs=visual-studio-mac</a></p>
  
  <p>and ran it locally and it worked inside of visual studio - it spun up at localhost:5000, and I even used the sample view they had to perform some SignalR commands. Everything looked great! <strong>It works!</strong></p>
  
  <p>Now I'm trying to utilize <a href="https://github.com/adamhartford/SwiftR" rel="nofollow noreferrer">SwiftR</a> and basically just do a simple call out to  SignalR running locally to prove it works in Swift. (<a href="http://localhost:5000/chatHub" rel="nofollow noreferrer">http://localhost:5000/chatHub</a>)</p>
  
  <p>I'm getting the error: Error during negotiation request</p>
  
  <p>The output is this:</p>
  
  <pre><code>started
  Error: Optional(["message": Error during negotiation request.])
  disconnected
  </code></pre>
  
  <p>Here is my code - any ideas what's going on? I'm using the exact code Microsoft provided (which seems to run fine) but Swift isn't liking it.</p>
  
  <p>In my podfile, i'm just using</p>
  
  <pre><code>pod 'SwiftR'
  </code></pre>
  
  <p>and in a misc viewController to test it out, I'm doing this:</p>
  
  <pre><code>func testThis()
      {
          // Client
          let connection = SignalR("http://localhost:5000/chatHub")
  
          let simpleHub = Hub("ChatHub")
          simpleHub.on("SendMessage") { args in
              let message = args![0] as! String
              let detail = args![1] as! String
              print("Message: \(message)\nDetail: \(detail)")
          }
  
          connection.addHub(simpleHub)
          connection.starting = { print("started") }
          connection.connected = { print("connected: \(connection.connectionID)") }
          connection.connectionSlow = { print("connectionSlow") }
          connection.reconnecting = { print("reconnecting") }
          connection.reconnected = { print("reconnected") }
          connection.disconnected = { print("disconnected") }
          connection.error = { error in
              print("Error: \(error)")
  
              if let source = error?["source"] as? String, source == "TimeoutException" {
                  print("Connection timed out. Restarting...")
                  connection.start()
              }
          }
          connection.start()
  
          do {
              try
              // Invoke server method
              simpleHub.invoke("SendMessage", arguments: ["Simple Test", "This is a simple message"])
          }
          catch {
              print(error)
          }
          // Invoke server method and handle response
            do {
              try simpleHub.invoke("SendMessage", arguments: ["Simple Test", "This is a simple message"]) { (result, error) in
              if let e = error {
                  print("Error: \(e)")
              } else {
                  print("Success!")
                  if let r = result {
                      print("Result: \(r)")
                  }
              }
          }
          }
            catch {
              print(error)
          }
      }
  </code></pre>
  
  <p>in viewDidLoad() i'm just calling testThis()</p>
  
  <p>I even modified the .net code to allow cors like this:</p>
  
  <pre><code>services.AddCors();
  </code></pre>
  
  <p>and then further down</p>
  
  <pre><code> app.UseCors(cors =&gt;
              {
                  cors.AllowAnyHeader();
                  cors.AllowAnyOrigin();
                  cors.AllowAnyMethod();
              });
  </code></pre>
  
  <p>but it still continues to say</p>
  
  <pre><code>Error: Optional(["message": Error during negotiation request.])
  </code></pre>
  
  <p>Really appreciate any insight anyone can offer!</p>