Skip to content

Commit

Permalink
Use the real request content length when building authorization heade…
Browse files Browse the repository at this point in the history
…r signature
  • Loading branch information
Votocek Jan authored and Votocek Jan committed Jun 16, 2017
1 parent 8fe9425 commit f10f1c3
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 f10f1c3

Please sign in to comment.