public RemoteBulkInsertOperation(BulkInsertOptions options, ServerClient client) { this.options = options; this.client = client; items = new BlockingCollection <RavenJObject>(options.BatchSize * 8); string requestUrl = "/bulkInsert?"; if (options.CheckForUpdates) { requestUrl += "checkForUpdates=true"; } if (options.CheckReferencesInIndexes) { requestUrl += "&checkReferencesInIndexes=true"; } var expect100Continue = client.Expect100Continue(); // this will force the HTTP layer to authenticate, meaning that our next request won't have to HttpJsonRequest req = client.CreateRequest("POST", requestUrl + "&op=generate-single-use-auth-token", disableRequestCompression: true); var token = req.ReadResponseJson(); httpJsonRequest = client.CreateRequest("POST", requestUrl, disableRequestCompression: true); // the request may take a long time to process, so we need to set a large timeout value httpJsonRequest.PrepareForLongRequest(); httpJsonRequest.AddOperationHeader("Single-Use-Auth-Token", token.Value <string>("Token")); nextTask = httpJsonRequest.GetRawRequestStream() .ContinueWith(task => { try { expect100Continue.Dispose(); } catch (Exception) { } WriteQueueToServer(task); }); }