         let session = NSURLSession.sharedSession()
         let loginURLString = host + "/trader/desktop/auth/login"
         let request = NSMutableURLRequest(URL: NSURL(string: loginURLString)!)
+        request.HTTPMethod = "POST"
+        request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
+//        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
+        
         let param = ["id" : "shawn@nogle.com", "pass" : "Shawn123"]
-//        var parts = [String]()
-//        for (key, value) in param {
-//            let field = key + "=" + value
-//            parts.append(field)
-//        }
-//        let string = parts.joinWithSeparator("&")
-//        let stringData = string.dataUsingEncoding(NSUTF8StringEncoding)!
-        let data = try! NSJSONSerialization.dataWithJSONObject(param, options: NSJSONWritingOptions(rawValue: 0))
-        request.HTTPMethod = "POST"
-//        request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
-        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
+        let string = convertToQueryString(param)
+        let data = string.dataUsingEncoding(NSUTF8StringEncoding)!
+//        let data = try! NSJSONSerialization.dataWithJSONObject(param, options: NSJSONWritingOptions(rawValue: 0))
         request.HTTPBody = data
+        
         let task = session.dataTaskWithRequest(request) { (data, response, error) in
             let res = response as! NSHTTPURLResponse
             if res.statusCode == 200 {
-                self.parseCookies(res)
-                
+                let fields = res.allHeaderFields as! [String : String]
+                let cookies = NSHTTPCookie.cookiesWithResponseHeaderFields(fields, forURL: res.URL!)
+                let cookie = cookies.filter({
+                    $0.name == "JSESSIONID"
+                }).first!
+                self.socket.headers["Cookie"] = cookie.name + "=" + cookie.value
                 self.client.connect()
             } else {
                 debugPrint(res)
-                XCTAssert(false, "Status code isn't 200")
+                XCTAssert(false, "Status code isn't 200. Login failed.")
                 delegate.expectation.fulfill()
             }
         }

    
    func stompClient(client: StompClient, didReceivedData data: NSData) {
        let json = try! NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
        debugPrint(json)
//        XCTAssert(json is [AnyObject], "Reveived data isn't an array.")
        
        client.unsubscribe(destination)
        

    
    private var client: StompClient!
    private var socket: WebSocket!
    private let host = "http://10.1.10.113:8080"
    
    override func setUp() {
        super.setUp()
