本文整理汇总了C#中RestClient.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.AddParameter方法的具体用法?C# RestClient.AddParameter怎么用?C# RestClient.AddParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestClient
的用法示例。
在下文中一共展示了RestClient.AddParameter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}