本文整理汇总了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);
}
示例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);
}