public SasParameters(string sasToken) { SasToken = sasToken.TrimStart('?'); foreach (string parameter in SasToken.Split('&')) { string paramName = parameter.ToLower().Split('=')[0]; string encodedParamValue = parameter.Split('=')[1]; string paramValue = WebUtility.UrlDecode(encodedParamValue); if (paramName.Equals("api-version")) { ApiVersion = paramValue; } if (paramName.Equals("sv")) { SignedVersion = paramValue; } if (paramName.Equals("ss")) { SignedServices = paramValue; } if (paramName.Equals("srt")) { SignedResourceTypes = paramValue; } if (paramName.Equals("sp")) { SignedPermission = paramValue; } if (paramName.Equals("sip")) { SignedIp = paramValue; } if (paramName.Equals("spr")) { SignedProtocol = paramValue; } if (paramName.Equals("sig")) { Signature = encodedParamValue; } if (paramName.Equals("st")) { SignedStart = paramValue; SignedStartUtc = ParseDate(SignedStart); SignedStartLocal = SignedStartUtc.ToLocalTime(); } if (paramName.Equals("se")) { SignedExpiry = paramValue; SignedExpiryUtc = ParseDate(SignedExpiry); SignedExpiryLocal = SignedExpiryUtc.ToLocalTime(); } // service sas if (paramName.Equals("sr") | paramName.Equals("tn")) { IsServiceSas = true; } } }
public virtual async Task Send(byte[] content) { var c = new HttpClient(); c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SharedAccessSignature", SasToken.Split(' ')[1]); try { var endpoint = GetEndpoint(); Console.Write($"Sending byte array to {endpoint}..."); var result = await c.PostAsync(endpoint, new ByteArrayContent(content)); if (result.IsSuccessStatusCode) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Success"); Console.ForegroundColor = ConsoleColor.White; return; } Console.WriteLine(await result.Content.ReadAsStringAsync()); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(e); Console.ForegroundColor = ConsoleColor.White; } }