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


C# HttpWebRequest.SignRequest方法代码示例

本文整理汇总了C#中System.Net.HttpWebRequest.SignRequest方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebRequest.SignRequest方法的具体用法?C# HttpWebRequest.SignRequest怎么用?C# HttpWebRequest.SignRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.HttpWebRequest的用法示例。


在下文中一共展示了HttpWebRequest.SignRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPageStarted

			public override void OnPageStarted (WebView view, string url, Android.Graphics.Bitmap favicon)
			{
				if (!url.StartsWith (RedirectUri) || this.tcs.Task.IsCompleted)
					return;

				this.view.Visibility = ViewStates.Gone;

				var values = ParseQueryString (new Uri (url).Query);

				if (values["oauth_token"] != this.token)
				{
					this.tcs.SetException (new Exception ("Invalid token"));
					return;
				}

				this.verifier = values ["oauth_verifier"];

				HttpWebRequest request = new HttpWebRequest (new Uri ("https://api.twitter.com/oauth/access_token"));
				request.Method = "POST";
				request.SignRequest (new Tokens
				{
					ConsumerKey = ConsumerKey,
					ConsumerSecret = ConsumerSecret,
					AccessToken = this.token,
					AccessTokenSecret = this.secret
				}).InHeader();

				using (StreamWriter writer = new StreamWriter (request.GetRequestStream()))
				{
					writer.Write ("oauth_verifier=" + this.verifier);
					writer.Flush();
				}

				try
				{
					HttpWebResponse httpresponse = (HttpWebResponse)request.GetResponse();
					using (Stream rstream = httpresponse.GetResponseStream())
					using (StreamReader reader = new StreamReader (rstream))
					{
						string response = Uri.UnescapeDataString (reader.ReadToEnd());
						var parts = ParseQueryString (response);

						this.tcs.SetResult (new Tuple<string, string> (parts ["oauth_token"], parts ["oauth_token_secret"]));
					}
				}
				catch (WebException ex)
				{
					this.tcs.SetException (ex);
				}

				base.OnPageStarted (view, url, favicon);
			}
开发者ID:numo16,项目名称:StackMob.NET,代码行数:52,代码来源:TwitterActivity.cs

示例2: Auth

			public void Auth()
			{
				this.view.Visibility = ViewStates.Visible;

				HttpWebRequest request = new HttpWebRequest (new Uri ("https://api.twitter.com/oauth/request_token"));
				request.SignRequest (new Tokens { ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret })
					.WithCallback (RedirectUri)
					.InHeader();

				try
				{
					HttpWebResponse response = (HttpWebResponse)request.GetResponse();
					using (Stream rstream = response.GetResponseStream())
					using (StreamReader reader = new StreamReader (rstream))
					{
						string rcontents = reader.ReadToEnd();
						var values = ParseQueryString (rcontents);
						if (values["oauth_callback_confirmed"] != "true")
						{
							this.tcs.SetException (new Exception ("Callback not confirmed"));
							return;
						}

						this.token = values ["oauth_token"];
						this.secret = values ["oauth_token_secret"];
					}
				}
				catch (Exception ex)
				{
					this.tcs.SetException (ex);
					return;
				}

				this.view.LoadUrl ("https://api.twitter.com/oauth/authenticate?oauth_token=" + this.token);
			}
开发者ID:numo16,项目名称:StackMob.NET,代码行数:35,代码来源:TwitterActivity.cs


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