Skip to content

Commit

Permalink
Merge pull request #7 from Votok/master
Browse files Browse the repository at this point in the history
Use the real request content length
  • Loading branch information
ealsur authored Jun 16, 2017
2 parents 8fe9425 + f10f1c3 commit 27b80d4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions HTTPDataCollectorAPI/Collector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ public async Task Collect(string LogType, object ObjectToSerialize, string ApiVe
/// <param name="ApiVersion">Optional. Api Version.</param>
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";
Expand All @@ -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);
Expand Down

0 comments on commit 27b80d4

Please sign in to comment.