title: "Stream is sending an event before being opened"
body: <p>I'm trying to make a SOAP request with Swift. Running the latest Xcode/iOS as of 9/9/14. I use an <code>NSMutableURLRequest</code> that I add an HTTPBody to with the request info. However, Once I start an <code>NSURLConnection</code> with the request, I get an error "Stream xxxxxxxxx is sending an event before being opened". I'm not using any networking libraries, just a plain old <code>NSURLConnection</code>. Any thoughts on what could cause this error? Thanks!</p>
  
  <p>Relevant code in use:</p>
  
  <pre><code>func createSOAPRequestWithEnvelope(soapEnvelope : String) {
      //create request
      var url = NSURL(string: "https://my-service-url")
      var req = NSMutableURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: 5000)
  
      req.addValue("text/xml",    forHTTPHeaderField: "Content-Type")
      req.HTTPMethod = "POST"
      req.HTTPBody = soapEnvelope.dataUsingEncoding(NSUTF8StringEncoding)
  
      //begin connection
      var connection = NSURLConnection(request: req, delegate: self, startImmediately: false)
      connection.scheduleInRunLoop(NSRunLoop.mainRunLoop(), forMode: NSDefaultRunLoopMode)
  
      connection.start() //error happens after this command :(
  }
  
  //takes care of NTLM Authentication
  func connection(connection: NSURLConnection!, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge!) {
      var authMethod = challenge.protectionSpace.authenticationMethod
  
      if authMethod == NSURLAuthenticationMethodNTLM {
          var credential = NSURLCredential(user: self.username,
              password: self.password,
              persistence: NSURLCredentialPersistence.ForSession)
  
          challenge.sender.useCredential(credential, forAuthenticationChallenge: challenge)
      }
  }
  
  func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
      // Response received, clear out data
      self.transactionData = NSMutableData()
  }
  
  func connection(connection: NSURLConnection!, didReceiveData data: NSData!) {
      // Store received data
      self.transactionData?.appendData(data)
  }
  </code></pre>