         request.setValue("application/json", forHTTPHeaderField: "Content-Type")
 		request.httpBody = jsonData
         request = authenticate(request)
+        print("POST to \(url) -> \(request)")
 		
 		let session = URLSession(configuration: URLSessionConfiguration.ephemeral)
-		task = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in
+		task = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
 			
             guard let httpStatus = response as? HTTPURLResponse, let data = data, error == nil else {
-                print("POST \(url) -> \(error!)")
+                print("POST to \(url) -> \(error!)")
                 failure(error!)
                 return
             }
-			print("status code = \(httpStatus.statusCode)")
-//            RCLogO( NSString(data: data!, encoding: 0));
-
-            if let d = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments)  {
-                success(d)
-            } else {
-                print("Not a valid json for url \(url)")
-                failure(RCHttpError(errorDescription: "Invalid json response"))
-            }
+            print("POST to \(url) response: \(String(data: data, encoding: .utf8) ?? "") -> status code = \(httpStatus.statusCode)")
+            success(data)
 		})
-		task?.resume()
+		task!.resume()
 	}
 	
     //mark: put data sync and async
     
-    func put (at path: String, parameters: [String: Any], success: @escaping (Any) -> Void, failure: @escaping (Error) -> Void) {
+    func put (at path: String, parameters: [String: Any], success: @escaping (Data) -> Void, failure: @escaping (Error) -> Void) {
         
-        guard baseURL != nil else {
-            fatalError("URL was not set")
-        }
         let fullPath = baseURL.appendingPathComponent(path).absoluteString.removingPercentEncoding!
         let url = URL(string: fullPath)!
         let jsonData = try! JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)

//		request.HTTPBody = postData
		
		let session = URLSession( configuration: URLSessionConfiguration.ephemeral)
		task = session.uploadTask(with: request as URLRequest, from: data, completionHandler: { (data_, response_, error_) -> Void in
			var json :NSDictionary? = nil;
			
			if (error_ != nil) {
				let e: NSErrorPointer? = nil
				var response_dict: Any?
				do {
					response_dict = try JSONSerialization.jsonObject(with: data_!, options: JSONSerialization.ReadingOptions.allowFragments)
				} catch _ as NSError {
//					e??.memory = error
					response_dict = nil
				} catch {
					fatalError()
				};
				//				println(response_dict);
				if (e! == nil) {
					json = ["text": "Json parse error"]
				}
				else {
					json = response_dict as? NSDictionary
				}
				completion(json!);
			}
			error(["text": "Download error"])
		})
		task?.resume()
	}
	
	func cancel () {
		task?.cancel()
	}
	
	func downloadStarted () {
#if os(iOS)
		UIApplication.shared.isNetworkActivityIndicatorVisible = true
#endif
	}
	
	func downloadEnded () {
#if os(iOS)
		UIApplication.shared.isNetworkActivityIndicatorVisible = false
#endif
	}

    private func authenticate (_ request: URLRequest) -> URLRequest {
        var req = request
        if let user = self.user, let password = self.password {
            let loginData = "\(user):\(password)".data(using: String.Encoding.utf8)!
            let base64LoginData = loginData.base64EncodedString()
            req.setValue("Basic \(base64LoginData)", forHTTPHeaderField: "Authorization")
        }
        return req

        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpBody = jsonData
        request = authenticate(request)
        print("PUT to \(url) -> \(request)")
        
        let session = URLSession(configuration: URLSessionConfiguration.ephemeral)
        task = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
            
            guard let httpStatus = response as? HTTPURLResponse, let data = data, error == nil else {
                print("PUT to \(url) -> \(error!)")
                failure(error!)
                return
            }
            print("PUT to \(url) response: \(String(data: data, encoding: .utf8) ?? "") -> status code = \(httpStatus.statusCode)")
            success(data)
        })
        task!.resume()
    }
    
	func upload (data: Data, filename: String, completion: @escaping (NSDictionary) -> Void, error: @escaping (NSDictionary) -> Void) {
