本文整理汇总了C#中RestClient.BeginRequest方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.BeginRequest方法的具体用法?C# RestClient.BeginRequest怎么用?C# RestClient.BeginRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestClient
的用法示例。
在下文中一共展示了RestClient.BeginRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTwitterToken
private void GetTwitterToken()
{
var credentials = new OAuthCredentials
{
Type = OAuthType.RequestToken,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = Constants.ConsumerKey,
ConsumerSecret = Constants.ConsumerKeySecret,
Version = Constants.OAuthVersion,
CallbackUrl = Constants.CallbackUri
};
var client = new RestClient
{
Authority = "https://api.twitter.com/oauth",
Credentials = credentials,
HasElevatedPermissions = true,
SilverlightAcceptEncodingHeader = "gizp",
DecompressionMethods = DecompressionMethods.GZip,
};
var request = new RestRequest
{
Path = "/request_token"
};
client.BeginRequest(request, new RestCallback(TwitterRequestTokenCompleted));
}
示例2: ApplicationBarIconButton_Click
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
RestClient client2 = new RestClient
{
Authority = "https://graph.facebook.com/",
};
RestRequest request2 = new RestRequest
{
Path = "/me/feed?message=" + WatermarkTB.Text
};
if (imgstream != null)
{
string albumId = (string)settings["facebook_photo"];
request2 = new RestRequest
{
Path = albumId + "/photos?message=" + WatermarkTB.Text
};
request2.AddFile("photo", "image.jpg", imgstream);
}
request2.AddField("access_token", (string)settings["facebook_token"]);
var callback = new RestCallback(
(restRequest, restResponse, userState) =>
{
// Callback when signalled
}
);
client2.BeginRequest(request2, callback);
MessageBox.Show("Share successfully.", "Thanks", MessageBoxButton.OK);
this.NavigationService.GoBack();
}
示例3: GetFriends
public static void GetFriends(EventHandler<FriendsListEventArgs> callback)
{
var serializer = new Hammock.Serialization.HammockDataContractJsonSerializer();
RestClient client = new RestClient
{
Authority = baseUrl,
Timeout = new TimeSpan(0, 0, 0, _timeOut),
Serializer = serializer,
Deserializer = serializer
};
RestRequest request = new RestRequest
{
Path = "GetFriends" + "?timestamp=" + DateTime.Now.Ticks.ToString(),
Timeout = new TimeSpan(0, 0, 0, _timeOut)
};
friendscallback = callback;
try
{
client.BeginRequest(request, new RestCallback<List<Friend>>(GetFriendsCallback));
}
catch (Exception ex)
{
friendscallback.Invoke(null, new FriendsListEventArgs() { Friends = null, Error = new WebException("Communication Error!", ex) });
}
}
示例4: UploadString
/// <summary>
/// 上传数据
/// </summary>
/// <param name="url"></param>
/// <param name="service"></param>
/// <param name="queries"></param>
/// <param name="action"></param>
/// <param name="failed"></param>
protected void UploadString(string url
, IDictionary<string, string> queries
, Action<RestResponse, object> action
, Action<Exception> failed
, object userState)
{
bool httpResult = HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
RestClient client = new RestClient();
client.Method = WebMethod.Post;
queries.ToList().ForEach(o => client.AddParameter(o.Key, o.Value));
client.AddHeader("X-Requested-With", "xmlhttp");
client.Authority = url;
RestRequest restRequest = new RestRequest();
CookieContainer cookieContainer = null;
if (IsolatedStorageSettings.ApplicationSettings.Contains("cookie"))
{
cookieContainer = IsolatedStorageSettings.ApplicationSettings["cookieContainer"] as CookieContainer;
Cookie cookie = IsolatedStorageSettings.ApplicationSettings["cookie"] as Cookie;
if (cookieContainer.Count == 0 && cookie != null)
{
cookieContainer.SetCookies(new Uri(Constant.ROOTURL), string.Format("{0}={1}", cookie.Name, cookie.Value));
}
}
else
{
cookieContainer = new CookieContainer();
}
restRequest.CookieContainer = cookieContainer;
client.BeginRequest(restRequest, (request, response, userState1) =>
{
cookieContainer = response.CookieContainer;
CookieCollection cookies = cookieContainer.GetCookies(new Uri(Constant.ROOTURL));
try
{
IsolatedStorageSettings.ApplicationSettings["cookie"] = cookies["cooper"];
IsolatedStorageSettings.ApplicationSettings["cookieContainer"] = cookieContainer;
IsolatedStorageSettings.ApplicationSettings.Save();
}
catch
{
}
if (response != null)
Deployment.Current.Dispatcher.BeginInvoke(action, response, userState1);
else
Deployment.Current.Dispatcher.BeginInvoke(failed, new Exception("response返回为空!"));
}, userState);
}
示例5: BeginGetAccessToken
public void BeginGetAccessToken(string code, RestCallback callback)
{
var oauthClient = new RestClient {Authority = _sslClient.Authority};
//Build an OAuth request manually - the Bit.ly documentation didn't indicate that I needed signatures
var request = new RestRequest {Method = WebMethod.Post, Path = "/oauth/access_token"};
request.AddParameter("client_id", Settings.ConsumerKey);
request.AddParameter("client_secret", Settings.ConsumerSecret);
request.AddParameter("code", code);
request.AddParameter("redirect_uri", Settings.RedirectUrl);
oauthClient.BeginRequest(request, callback);
}
示例6: DoRequest
//protected void DoRequest(string sEndpoint, WebMethod wmTransferType, Dictionary<string, string> dssParams, APIReturn aprReturn)
protected void DoRequest(RestRequest rrRequest, OAuthCredentials oaCredentials, APIReturn aprReturn)
{
//suggested by the smart guys at dev.twitter.com
rrRequest.AddParameter("oauth_callback", "oob");
RestClient rcClient = new RestClient
{
Authority = C_OAUTH_BASE_URL,
Credentials = oaCredentials
};
//post request, update credentials object
rcClient.BeginRequest(rrRequest, DoRequestCallback, aprReturn);
}
示例7: RefreshModelRssFeed
private static async void RefreshModelRssFeed(ProgressBarHelper progressBarHelper)
{
App.MainViewModel.RssItems.Clear();
string url = PreferenceHelper.GetPreference("RSS_FollowerPath");
if (string.IsNullOrEmpty(url))
{
progressBarHelper.PopTask();
return;
}
RestClient client = new RestClient();
RestRequest request = new RestRequest();
client.Authority = url;
request.Method = Method.Get;
RestResponse response = await client.BeginRequest(request);
if(response.Error == RestError.ERROR_SUCCESS && response.Content != null)
{
try
{
SyndicationFeed feed = new SyndicationFeed();
feed.Load(response.Content);
foreach (SyndicationItem item in feed.Items)
{
ItemViewModel model = RSSFeedConverter.ConvertFeedToCommon(item);
if (model != null)
{
App.MainViewModel.RssItems.Add(model);
}
}
}
catch (System.Exception ex)
{
DialogHelper.ShowToastDialog("RSS获取中发生错误,可能是网络问题,也可能是对应站点地址变更");
}
finally
{
progressBarHelper.PopTask();
}
}
else
{
DialogHelper.ShowToastDialog("RSS获取中发生错误,可能是网络问题,也可能是对应站点地址变更");
progressBarHelper.PopTask();
}
}
示例8: SendPicture
public void SendPicture(string text, string fileName, Stream file, Action<RestResponse, string> callback)
{
if (echoRequest == null)
echoRequest = new RestRequest();
RestClient client = new RestClient { Authority = "http://api.twitpic.com/", VersionPath = "1" };
echoRequest.AddFile("media", fileName, file);
echoRequest.AddField("key", "1abb1622666934158f4c2047f0822d0a");
echoRequest.AddField("message", text);
echoRequest.AddField("consumer_token", consumerKey);
echoRequest.AddField("consumer_secret", consumerKeySecret);
echoRequest.AddField("oauth_token", userKey);
echoRequest.AddField("oauth_secret", userKeySecret);
echoRequest.Path = "upload.xml";
//req.Method = Hammock.Web.WebMethod.Post;
client.BeginRequest(echoRequest, (RestCallback)uploadCompleted, callback);
}
示例9: CallDailyBurnApi
public static void CallDailyBurnApi(string apiExtensionPath, RestCallback callback, Dictionary<string, string> parameters)
{
string accessToken = HelperMethods.GetKeyValue("accessToken");
string accessTokenSecret = HelperMethods.GetKeyValue("accessTokenSecret");
var credentials = new OAuthCredentials
{
Type = OAuthType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = DailyBurnSettings.consumerKey,
ConsumerSecret = DailyBurnSettings.consumerKeySecret,
Token = accessToken,
TokenSecret = accessTokenSecret,
Version = "1.0"
};
var restClient = new RestClient
{
Authority = DailyBurnSettings.AuthorityUri,
HasElevatedPermissions = true,
Credentials = credentials,
Method = WebMethod.Get
};
var restRequest = new RestRequest
{
Path = apiExtensionPath,
Method = WebMethod.Get
};
if (parameters != null)
{
foreach (KeyValuePair<string, string> param in parameters)
{
restRequest.AddParameter(param.Key, param.Value);
}
}
restClient.BeginRequest(restRequest, new RestCallback(callback));
}
示例10: DoRequest
protected void DoRequest(string sEndpoint, WebMethod wmTransferType, Dictionary<string, string> dssParams, APIReturn aprReturn)
{
RestRequest rrRequest = new RestRequest();
rrRequest.Path = sEndpoint;
m_oaCredentials.Type = OAuthType.ProtectedResource;
m_oaCredentials.Verifier = null;
foreach (KeyValuePair<string, string> kvpCur in dssParams)
rrRequest.AddParameter(kvpCur.Key, kvpCur.Value);
RestClient rcClient = new RestClient
{
Authority = C_BASE_URL,
VersionPath = "1",
Credentials = m_oaCredentials,
Method = wmTransferType
};
rcClient.BeginRequest(rrRequest, DoRequestCallback, aprReturn);
}
示例11: HammockHttpClient
public HammockHttpClient(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitConnection)
{
this.client = new RestClient { Authority = baseUri.ToString() };
client.AddHeader("Accept", "application/json");
client.AddHeader("Content-Type", "application/json; charset=utf-8");
client.ServicePoint = System.Net.ServicePointManager.FindServicePoint(baseUri);
#if ! MONO
client.ServicePoint.SetTcpKeepAlive(true, 300, 30);
#endif
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
var credentials = username + ":" + password;
var base64Credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
client.AddHeader("Authorization", "Basic " + base64Credentials);
}
client.Timeout = timeout;
client.RetryPolicy = new RetryPolicy
{
RetryConditions =
{
new Hammock.Retries.NetworkError(),
new Hammock.Retries.Timeout(),
new Hammock.Retries.ConnectionClosed()
},
RetryCount = 3
};
client.BeforeRetry += new EventHandler<RetryEventArgs>(client_BeforeRetry);
//The first time a request is made to a URI, the ServicePointManager
//will create a ServicePoint to manage connections to a particular host
//This process is expensive and slows down the first created view.
//The call to BeginRequest is basically an async, no-op HTTP request to
//initialize the ServicePoint before the first view request is made.
if (shouldInitConnection) client.BeginRequest();
}
示例12: SearchByKey
private async void SearchByKey(String key)
{
if (m_progressBarHelper == null)
m_progressBarHelper = new ProgressBarHelper(LoadProgessBar, () => { });
m_progressBarHelper.PushTask();
RestClient client = new RestClient();
RestRequest request = new RestRequest();
client.Authority = "http://www.search4rss.com/search.php";
request.Method = Method.Get;
request.AddParameter("lang", "en");
request.AddParameter("q", key);
RestResponse response = await client.BeginRequest(request);
if (response.Error == RestError.ERROR_SUCCESS && response.Content != null)
{
HandleHtml(response.Content);
}
else
{
DialogHelper.ShowMessageDialog("网络无法连接,请检查当前网络状态。");
m_progressBarHelper.PopTask();
}
}
示例13: photoChooserTask_Completed
private void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
img_bool = true;
var client = new RestClient
{
Authority = "http://api.twipl.net/",
VersionPath = "1",
};
var request = new RestRequest
{
Path = "upload.json" // can be upload.xml or whatever, but you have to parse it accordingly
};
request.AddFile("media1", "img.jpg", e.ChosenPhoto);
request.AddField("key", "b76ecda29f7c47e0bfefd0b458e91fb5");
request.AddField("oauth_token", (string)settings["twitter_token"]);
request.AddField("oauth_secret", (string)settings["twitter_tokensecret"]);
request.AddField("message", "");
client.BeginRequest(request, new RestCallback(Callback));
}
}
示例14: postMessageToTwitter
private void postMessageToTwitter()
{
var credentials = new OAuthCredentials
{
Type = OAuthType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = AppSettings.TwitterConsumerKey,
ConsumerSecret = AppSettings.TwitterConsumerKeySecret,
Token = this.accessToken,
TokenSecret = this.accessTokenSecret,
Version = "1.0"
};
var restClient = new RestClient
{
Authority = AppSettings.TwitterStatusUpdateUrl,
HasElevatedPermissions = true,
Credentials = credentials,
Method = WebMethod.Post
};
restClient.AddHeader("Content-Type", "application/x-www-form-urlencoded");
var restRequest = new RestRequest
{
Path = "1/statuses/update.xml?status=" + this.postMessage
};
var ByteData = Encoding.UTF8.GetBytes(this.postMessage);
restRequest.AddPostContent(ByteData);
restClient.BeginRequest(restRequest, new RestCallback(postFinished));
}
示例15: ApplicationBarIconButton_Click
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
if (WatermarkTB.Text == emptystr)
{
MessageBox.Show("Please input your mind :)", "Sorry", MessageBoxButton.OK);
return;
}
RestClient client2 = new RestClient
{
Authority = "https://graph.facebook.com/",
};
RestRequest request2 = new RestRequest
{
Path = id+"/comments?message=" + WatermarkTB.Text
};
request2.AddField("access_token", (string)settings["facebook_token"]);
var callback = new RestCallback(
(restRequest, restResponse, userState) =>
{
Dispatcher.BeginInvoke(delegate()
{
ScrollViewer.Height = 680;
ScrollViewer.UpdateLayout();
ScrollViewer.ScrollToVerticalOffset(double.MaxValue);
WatermarkTB.Text = emptystr;
keyboard.txt = "";
keyboard.Init();
KeyboardPanel.Visibility = Visibility.Collapsed;
comment_list.Children.Clear();
loadpg.Visibility = Visibility.Visible;
SolidColorBrush Brush1 = new SolidColorBrush();
Brush1.Color = Colors.Gray;
WatermarkTB.Foreground = Brush1;
});
string url = String.Format("https://graph.facebook.com/{0}?access_token={1}", id, (string)settings["facebook_token"]);
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_openHandler);
wc.DownloadStringAsync(new Uri(url), UriKind.Absolute);
}
);
client2.BeginRequest(request2, callback);
}