本文整理汇总了C#中RestClient.Request方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.Request方法的具体用法?C# RestClient.Request怎么用?C# RestClient.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestClient
的用法示例。
在下文中一共展示了RestClient.Request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: fetchXml
public void fetchXml()
{
User = usernamBox.Text.Replace(" ", "").Replace("/", "").Replace(".", "");
URL = new Uri("http://" + User + ".tumblr.com/api/read/json");
int max = 0;
var client = new RestClient();
client.Authority = URL.ToString();
var request = new RestRequest();
request.AddParameter("type", "photo");
request.AddParameter("num", "50");
request.AddParameter("filter", "text");
var r1 = client.Request(request);
var t = r1.Content.ToString().Replace("var tumblr_api_read = ", "");
var firstResponse = JsonParser.FromJson(t);
max = Convert.ToInt32(firstResponse["posts-total"]);
// to eventually make each fetch a separate request
for (int i = 0; i < max; i += 51)
{
if (i != 0)
{
request.AddParameter("start", i.ToString());
}
var r2 = client.Request(request);
var t2 = r2.Content.ToString().Replace("var tumblr_api_read = ", "");
var Response = JsonParser.FromJson(t2);
getUrls(Response.ToDictionary(x => x.Key, x => x.Value));
}
}
示例2: RetrieveTweets
private static string RetrieveTweets(string sinceId)
{
BasicAuthCredentials credentials = new BasicAuthCredentials
{
Username = WebConfigurationManager.AppSettings["ScreenName"],
Password = WebConfigurationManager.AppSettings["SuperTweetPassword"]
};
RestClient client = new RestClient
{
Authority = "http://api.supertweet.net",
VersionPath = "1"
};
string possibleSinceId = string.IsNullOrWhiteSpace(sinceId) ? "": string.Format("&since_id={0}", sinceId) ;
RestRequest request = new RestRequest
{
Credentials = credentials,
Path = string.Format("statuses/home_timeline.json?count=200&include_entities=false{0}", possibleSinceId)
};
RestResponse response = client.Request(request);
var content = response.Content;
return content;
}
示例3: Index
public ActionResult Index()
{
var restConfig = RestConfig.Current;
if (string.IsNullOrEmpty(restConfig.UserId))
return RedirectToAction("Authorize");
var client = new RestClient {Authority = restConfig.BaseUrl};
var request = new RestRequest
{
Path = string.Format("users/{0}/queues/instant", restConfig.UserId),
Credentials = OAuthCredentials.ForProtectedResource(
restConfig.OAuthKey, restConfig.OAuthSharedSecret,
restConfig.OAuthToken, restConfig.OAuthTokenSecret)
};
var response = client.Request(request);
if (response.StatusCode == HttpStatusCode.OK)
{
var xml = XDocument.Parse(response.Content);
var items = from i in xml.Descendants("queue_item")
select new Movie
{
Title = (string) i.Descendants("title").Attributes("regular").FirstOrDefault(),
Thumbnail = (string)i.Descendants("box_art").Attributes("small").FirstOrDefault(),
ReleaseYear = (string)i.Descendants("release_year").FirstOrDefault(),
Link = (string)i.Descendants("link").Where(x => (string) x.Attribute("rel") == "alternate").Attributes("href").FirstOrDefault()
};
var model = new {Response = response, Items = items}.ToExpando();
return View(model);
}
return View(new {Response = response, Items = (object) null}.ToExpando());
}
示例4: GetFavorites
public RestResponse GetFavorites(string user, int page, int pageSize)
{
// Documentation for GET /favorites
// https://dev.twitter.com/docs/api/1/get/favorites
// Create the REST Client
var client = new RestClient {Authority = "http://api.twitter.com/1"};
// Create the REST Request
var request = new RestRequest {Path = "favorites.json", Method = WebMethod.Get};
request.AddParameter("id", user);
request.AddParameter("page", page.ToString());
request.AddParameter("count", pageSize.ToString());
// Set API authentication tokens
var appSettings = ConfigurationManager.AppSettings;
request.Credentials = OAuthCredentials.ForProtectedResource(
appSettings["ConsumerKey"], appSettings["ConsumerSecret"], appSettings["Token"],
appSettings["TokenSecret"]);
// Make request
var response = client.Request(request);
return response;
}
示例5: MakeYahooPostSample
public string MakeYahooPostSample()
{
var client = new RestClient
{
Authority = "http://api.search.yahoo.com/ContentAnalysisService",
VersionPath = "V1"
};
var request = new RestRequest
{
Path = "termExtraction",
Method = WebMethod.Post
};
var appId = "YahooDemo";
var context = "Italian sculptors and painters of the renaissance favored the Virgin Mary for inspiration";
var query = "madonna";
request.AddField("appid", appId);
request.AddField("context", context);
request.AddField("query", query);
var response = client.Request(request);
return response.Content;
}
示例6: UpdateStatus
/// <summary>
/// ステータスを更新します
/// </summary>
/// <param name="accessToken"></param>
/// <param name="accessTokenSecret"></param>
/// <param name="message"></param>
/// <returns></returns>
public static dynamic UpdateStatus(string accessToken, string accessTokenSecret, string message)
{
var client = new RestClient
{
Authority = "http://api.twitter.com",
UserAgent = "OAuthSample",
};
var credentials = OAuthCredentials.ForProtectedResource(
Config.TwitterConsumerKey,
Config.TwitterConsumerSecret,
accessToken,
accessTokenSecret);
credentials.ParameterHandling = OAuthParameterHandling.UrlOrPostParameters;
var request = new RestRequest
{
Path = "statuses/update.json",
Method = WebMethod.Post,
Credentials = credentials,
};
request.AddParameter("status", message);
var response = client.Request(request);
return DynamicJson.Parse(response.Content);
}
示例7: GetTwitterRedirectUrl
public string GetTwitterRedirectUrl(string consumerKey, string consumerSecret, string CallBackUrl)
{
OAuthCredentials credentials = new OAuthCredentials()
{
Type = OAuthType.RequestToken,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = consumerKey,
ConsumerSecret = consumerSecret,
CallbackUrl = CallBackUrl
};
// Use Hammock to create a rest client
var client = new RestClient
{
Authority = "https://api.twitter.com/oauth",
Credentials = credentials
};
// Use Hammock to create a request
var request = new RestRequest
{
Path = "request_token"
};
// Get the response from the request
var response = client.Request(request);
var collection = HttpUtility.ParseQueryString(response.Content);
//string str = collection[1].ToString();
//HttpContext.Current.Session["requestSecret"] = collection[1];
string rest = "https://api.twitter.com/oauth/authorize?oauth_token=" + collection[0] + "~" + collection[1];
return rest;
}
示例8: GetUserInformation
/// <summary>
/// ログインユーザ情報を取得します
/// </summary>
/// <param name="accessToken"></param>
/// <returns></returns>
public static dynamic GetUserInformation(string accessToken)
{
// see http://developers.facebook.com/docs/reference/api/user/
var client = new RestClient { Authority = "https://graph.facebook.com/" };
var request = new RestRequest { Path = "me" };
request.AddParameter("access_token", accessToken);
var response = client.Request(request);
return DynamicJson.Parse(response.Content);
}
示例9: TweetImage
public RestResponse TweetImage(string imagePath, string imageName)
{
Hammock.RestRequest request = service.PrepareEchoRequest();
request.Path = "uploadAndPost.xml";
request.AddFile("media", imageName, imagePath, "image/jpeg");
request.AddField("key", "bb5654b0649cb63672affff5a232d772");
request.AddField("message", "ODE Bot at it again");
// Post photo to TwitPic with Hammock
RestClient client = new RestClient { Authority = "http://api.twitpic.com/", VersionPath = "2" };
RestResponse response = client.Request(request);
return response;
}
示例10: CreateLoginUsersStatusMessage
/// <summary>
/// ログインユーザのステータスメッセージを更新します
/// </summary>
/// <param name="accessToken"></param>
/// <param name="message"></param>
/// <returns></returns>
public static dynamic CreateLoginUsersStatusMessage(string accessToken, string message)
{
// see http://developers.facebook.com/docs/reference/api/user/
var client = new RestClient { Authority = "https://graph.facebook.com/" };
var request = new RestRequest
{
Path = "me/feed",
Method = Hammock.Web.WebMethod.Post,
};
request.AddParameter("access_token", accessToken);
request.AddParameter("message", message);
var response = client.Request(request);
return DynamicJson.Parse(response.Content);
}
示例11: Callback
public ActionResult Callback()
{
token = Request["oauth_token"];
verifier = Request["oauth_verifier"];
var credentials = new OAuthCredentials
{
ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"],
Token = token,
TokenSecret = token_secret,
Verifier = verifier,
Type = OAuthType.AccessToken,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
Version = "1.0"
};
var client = new RestClient { Authority = "https://api.linkedin.com/uas/oauth", Credentials = credentials, Method = WebMethod.Post };
var request = new RestRequest { Path = "accessToken" };
RestResponse response = client.Request(request);
string content = response.Content;
string accessToken = response.Content.Split('&').Single(s => s.StartsWith("oauth_token=")).Split('=')[1];
string accessTokenSecret = response.Content.Split('&').Single(s => s.StartsWith("oauth_token_secret=")).Split('=')[1];
//string accessToken = response.Content.Split('&').Where(s = > s.StartsWith("oauth_token=")).Single().Split('=')[1];
//string accessTokenSecret = response.Content.Split('&').Where(s = > s.StartsWith("oauth_token_secret=")).Single().Split('=')[1];
//var company = new LinkedInService(accessToken, accessTokenSecret).GetCompany(162479);
// Some commented call to API
//company = new LinkedInService(accessToken, accessTokenSecret).GetCompanyByUniversalName("linkedin");
// var companies = new LinkedInService(accessToken, accessTokenSecret).GetCompaniesByEmailDomain("apple.com");
// var companies1 = new LinkedInService(accessToken, accessTokenSecret).GetCompaniesByEmailDomain("linkedin.com");
// var companies2= new LinkedInService(accessToken, accessTokenSecret).GetCompaniesByIdAnduniversalName("162479", "linkedin");
//var people = new LinkedInService(accessToken, accessTokenSecret).GetPersonById("f7cp5sKscd");
//var people = new LinkedInService(accessToken, accessTokenSecret).GetCurrentUser();
//string url = Url.Encode("http://bd.linkedin.com/pub/rakibul-islam/37/522/653");
//var people = new LinkedInService(accessToken, accessTokenSecret).GetPeoPleByPublicProfileUrl(url);
//var peopleSearchresult = new LinkedInService(accessToken, accessTokenSecret).SearchPeopleByKeyWord("Princes");
//var peopleSearchresult = new LinkedInService(accessToken, accessTokenSecret).GetPeopleByFirstName("Mizan");
var currUser = new LinkedInService(accessToken,accessTokenSecret).GetCurrentUser();
//String companyName = company.Name;
return Content($"{currUser.FirstName} {currUser.LastName} {currUser.headLine}");
}
示例12: Can_use_specification_validation_to_block_request
public void Can_use_specification_validation_to_block_request()
{
var info = new DateTimeFormatInfo { Email = "nowhere" };
var client = new RestClient
{
Authority = "http://nowhere.com",
Info = info
};
var request = new RestRequest
{
Path = "fast"
};
client.Request(request);
}
示例13: Can_use_boolean_to_integer_validation_to_transform_parameter_value
public void Can_use_boolean_to_integer_validation_to_transform_parameter_value()
{
var info = new BooleanToIntegerInfo {IShouldBeANumber = false};
var client = new RestClient
{
Authority = "http://nowhere.com",
Info = info
};
var request = new RestRequest
{
Path = "fast"
};
client.Request(request);
}
示例14: Can_use_date_time_validation_to_transform_header_value
public void Can_use_date_time_validation_to_transform_header_value()
{
var info = new DateTimeFormatInfo {IAmADate = DateTime.Now };
var client = new RestClient
{
Authority = "http://nowhere.com",
Info = info
};
var request = new RestRequest
{
Path = "fast"
};
client.Request(request);
}
示例15: getFacebookData
void getFacebookData()
{
string CallbackUrl = "http://localhost:27393/facebookyeni/callback.aspx";
var client = new RestClient { Authority = "https://graph.facebook.com/oauth/" };
var request = new RestRequest { Path = "access_token" };
request.AddParameter("client_id", ConfigurationManager.AppSettings["FacebookClientId"]);
request.AddParameter("redirect_uri", CallbackUrl);
request.AddParameter("client_secret", ConfigurationManager.AppSettings["FacebookApplicationSecret"]);
request.AddParameter("code", Request["code"]);
RestResponse response = client.Request(request);
StringDictionary result = FacebookConnect.ParseQueryString(response.Content);
string aToken = result["access_token"];
responseFacebookUserInfo(aToken);
}