diff --git a/HTTPDataCollectorAPI/Collector.cs b/HTTPDataCollectorAPI/Collector.cs index 24dd98f..d8adc1b 100644 --- a/HTTPDataCollectorAPI/Collector.cs +++ b/HTTPDataCollectorAPI/Collector.cs @@ -45,9 +45,12 @@ public async Task Collect(string LogType, object ObjectToSerialize, string ApiVe /// Optional. Api Version. public async Task Collect(string LogType, string JsonPayload, string ApiVersion="2016-04-01", string timeGeneratedPropertyName = null) { + var utf8Encoding = new UTF8Encoding(); + Byte[] content = utf8Encoding.GetBytes(JsonPayload); + string url = "https://" + _WorkspaceId + ".ods.opinsights.azure.com/api/logs?api-version=" + ApiVersion; var rfcDate = DateTime.Now.ToUniversalTime().ToString("r"); - var signature = HashSignature("POST", JsonPayload.Length, "application/json", rfcDate, "/api/logs"); + var signature = HashSignature("POST", content.Length, "application/json", rfcDate, "/api/logs"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; @@ -60,8 +63,6 @@ public async Task Collect(string LogType, string JsonPayload, string ApiVersion= request.Headers["time-generated-field"] = timeGeneratedPropertyName; } request.Proxy = null; - var utf8Encoding = new UTF8Encoding(); - Byte[] content = utf8Encoding.GetBytes(JsonPayload); using (Stream requestStream = await request.GetRequestStreamAsync()) { requestStream.Write(content, 0, content.Length);