本文整理匯總了C#中System.Net.Http.HttpRequestMessage.SignRequest方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessage.SignRequest方法的具體用法?C# HttpRequestMessage.SignRequest怎麽用?C# HttpRequestMessage.SignRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.SignRequest方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
string payloadHash = null;
if (this.includePayloadHash &&
request.Method != HttpMethod.Get &&
request.Content != null)
{
var hmac = System.Security.Cryptography.HMAC.Create(credential.Algorithm);
hmac.Key = Encoding.ASCII.GetBytes(credential.Key);
var task = request.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
var payload = task.GetAwaiter().GetResult();
payloadHash = Convert.ToBase64String(hmac.ComputeHash(payload));
}
request.Headers.Host = request.RequestUri.Host;
request.SignRequest(credential,
this.ext,
this.ts,
this.nonce,
payloadHash);
return base.SendAsync(request, cancellationToken);
}
示例2: ShouldSignRequest
public void ShouldSignRequest()
{
var credential = new HawkCredential
{
Id = "456",
Algorithm = "hmacsha256",
Key = "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn",
User = "steve"
};
var date = DateTime.Now;
var ts = Hawk.ConvertToUnixTimestamp(date);
var mac = Hawk.CalculateMac("example.com:8080", "get", new Uri("http://example.com:8080/resource/4?filter=a"), "hello", ts.ToString(), "k3j4h2", credential, "header");
var authorization = string.Format("id=\"456\", ts=\"{0}\", nonce=\"k3j4h2\", mac=\"{1}\", ext=\"hello\"",
ts, mac);
var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com:8080/resource/4?filter=a");
request.SignRequest(credential, "hello", date, "k3j4h2", null);
Assert.IsNotNull(request.Headers.Authorization != null);
Assert.AreEqual(request.Headers.Authorization.Scheme, "Hawk");
Assert.AreEqual(request.Headers.Authorization.Parameter, authorization);
}
示例3: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
string payloadHash = null;
if (this.includePayloadHash &&
request.Method != HttpMethod.Get &&
request.Content != null)
{
payloadHash = Hawk.CalculatePayloadHash(await request.Content.ReadAsStringAsync().ConfigureAwait(false),
request.Content.Headers.ContentType.MediaType,
credential);
}
request.Headers.Host = request.RequestUri.Host;
request.SignRequest(credential,
this.ext,
this.ts,
this.nonce,
payloadHash);
return await base.SendAsync(request, cancellationToken);
}
示例4: Tweet
public void Tweet(string message)
{
string resourceUrl = Twitter.API_V1_1 + "statuses/update.json";
if (string.IsNullOrEmpty(message))
{
throw new TwitterClientException("Tweet cannot be empty.");
}
if (message.Length > 140)
{
throw new TwitterClientException("Tweet cannot be longer than 140 characters.");
}
// This is the content
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("status", message));
// Load content
HttpContent content = new FormUrlEncodedContent(postData);
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
// create a new Request Message
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, resourceUrl);
requestMessage.Content = content;
// Sign Request
requestMessage.SignRequest(postData, this.authorization);
var response = _client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).Result;
HandleErrors(response);
}