当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequestMessage.SignRequest方法代码示例

本文整理汇总了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);
        }
开发者ID:tugberkugurlu,项目名称:hawknet,代码行数:27,代码来源:HawkClientMessageHandler.cs

示例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);
        }
开发者ID:nordineb,项目名称:hawknet,代码行数:25,代码来源:HttpRequestMessageExtensionsTests.cs

示例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);
        }
开发者ID:linkypi,项目名称:hawknet,代码行数:23,代码来源:HawkClientMessageHandler.cs

示例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);
        }
开发者ID:jsturtevant,项目名称:twitter-stream,代码行数:31,代码来源:TwitterClient.cs


注:本文中的System.Net.Http.HttpRequestMessage.SignRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。