當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。