本文整理汇总了C#中RestClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.Get方法的具体用法?C# RestClient.Get怎么用?C# RestClient.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestClient
的用法示例。
在下文中一共展示了RestClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RaisesSendingEventForEachRequest
public void RaisesSendingEventForEachRequest()
{
_server.OnGet("/foo").RespondWith("awww yeah");
var client = new RestClient(BaseAddress);
var sendingEvents = new List<RequestDetails>();
client.Sending += (sender, args) => sendingEvents.Add(args.Request);
client.Get(BaseAddress + "/foo?omg=yeah");
Assert.That(sendingEvents.Single().RequestUri.PathAndQuery, Is.EqualTo("/foo?omg=yeah"));
Assert.That(sendingEvents.Single().Method, Is.EqualTo("GET"));
client.Get(BaseAddress + "/foo?omg=nah");
Assert.That(sendingEvents.Skip(1).Single().RequestUri.PathAndQuery, Is.EqualTo("/foo?omg=nah"));
Assert.That(sendingEvents.Skip(1).Single().Method, Is.EqualTo("GET"));
}
示例2: Details
public ActionResult Details(string code)
{
RestClient<Product> productsRestClient = new RestClient<Product>("http://localhost:3001/");
var product = productsRestClient.Get("products/code/" + code).Result;
// TODO: Fix this in EF
product.Supplier = new Supplier
{
Id = product.SupplierId,
Name = "My Supplier"
};
var productViewModel = new ProductViewModel()
{
Id = product.Id,
Code = product.Code,
Name = product.DisplayName,
Price = product.UnitPrice,
SupplierName = product.Supplier.Name
};
ProductViewModel another = Mapper.Map<ProductViewModel>(product);
return View(another);
}
示例3: AppliesAmbientOptionsToRedirects
public void AppliesAmbientOptionsToRedirects()
{
_server.OnGet("/redirect").RedirectTo("/x");
_server.OnGet("/x").Respond((req, res) => res.Body = req.Headers["x-foo"]);
var client = new RestClient(BaseAddress, new RequestHeader("x-foo", "yippee"));
var body = client.Get("/redirect").Body;
Assert.That(body, Is.EqualTo("yippee"));
}
示例4: RaisesErrorEventForRequestsWhenSendingThrows
public void RaisesErrorEventForRequestsWhenSendingThrows()
{
var client = new RestClient(new Uri(BaseAddress), new AlwaysThrowsOnSendingAdapter(), new List<PipelineOption>());
var sendErrors = new List<RequestErrorEventArgs>();
client.SendError += (sender, args) => sendErrors.Add(args);
Assert.That(() => client.Get("http://irrelevant"), Throws.InstanceOf<DeliberateException>());
Assert.That(sendErrors.Count, Is.EqualTo(1));
Assert.That(sendErrors[0].Exception, Is.InstanceOf<DeliberateException>());
}
示例5: RaisedErrorEventIncludesRequestDetails
public void RaisedErrorEventIncludesRequestDetails()
{
var client = new RestClient(BaseAddress, new AlwaysThrowsOnSendingAdapter(), new List<PipelineOption>());
var sendErrors = new List<RequestErrorEventArgs>();
client.SendError += (sender, args) => sendErrors.Add(args);
Assert.That(() => client.Get("http://howdy/"), Throws.InstanceOf<DeliberateException>());
Assert.That(sendErrors.Count, Is.EqualTo(1));
Assert.That(sendErrors[0].Request.RequestUri.AbsoluteUri, Is.EqualTo("http://howdy/"));
}
示例6: DoesNotRaiseRespondedEventForRequestsWhenSendingThrows
public void DoesNotRaiseRespondedEventForRequestsWhenSendingThrows()
{
_server.OnGet("/foo").Respond((req, res) => res.StatusCode = 418);
var client = new RestClient(new Uri(BaseAddress), new AlwaysThrowsOnSendingAdapter(), new List<PipelineOption>());
var respondedEvents = new List<ResponseDetails>();
client.Responded += (sender, args) => respondedEvents.Add(args.Response);
Assert.That(() => client.Get("/foo?omg=yeah"), Throws.InstanceOf<DeliberateException>());
Assert.That(respondedEvents, Is.Empty);
}
示例7: RaisesRespondedEventForEachRequest
public void RaisesRespondedEventForEachRequest()
{
_server.OnGet("/foo").Respond((req, res) => res.StatusCode = 418);
var client = new RestClient(BaseAddress);
var respondedEvents = new List<ResponseEventArgs>();
client.Responded += (sender, args) => respondedEvents.Add(args);
client.Get("/foo?teapot=yes", new ExpectStatus((HttpStatusCode)418));
Assert.That(respondedEvents.Single().Response.Status, Is.EqualTo(418));
Assert.That(respondedEvents.Single().Request.RequestUri.PathAndQuery, Is.EqualTo("/foo?teapot=yes"));
}
示例8: StillRaisesSendingEventWhenSendingThrows
public void StillRaisesSendingEventWhenSendingThrows()
{
var sendingEvents = new List<RequestDetails>();
var client = new RestClient(new Uri(BaseAddress), new AlwaysThrowsOnSendingAdapter(), new List<PipelineOption>());
client.Sending += (sender, args) => sendingEvents.Add(args.Request);
Assert.That(() => client.Get("/foo?omg=yeah"), Throws.InstanceOf<DeliberateException>());
Assert.That(sendingEvents.Single().RequestUri.PathAndQuery, Is.EqualTo("/foo?omg=yeah"));
Assert.That(sendingEvents.Single().Method, Is.EqualTo("GET"));
}
示例9: DisposingAResponseDisposesTheUnderlyingResponse
public void DisposingAResponseDisposesTheUnderlyingResponse()
{
var client = new TracksWhenDisposedClient();
var clientFactory = new StubAdapterFactory(client);
var restClient = new RestClient(new Uri("http://localhost"), clientFactory, new PipelineOption[0]);
var response = restClient.Get("oops");
Assert.That(client.Responses.Count, Is.EqualTo(1));
Assert.That(client.Responses[0].DisposeCount, Is.EqualTo(0));
response.Dispose();
Assert.That(client.Responses[0].DisposeCount, Is.EqualTo(1));
}
示例10: ManyConnectionsDoesNotThrowHttpRequestException
public void ManyConnectionsDoesNotThrowHttpRequestException()
{
var client = new RestClient(BaseAddress);
Assert.DoesNotThrow(() =>
{
// The max number of allowed outbound http requests on my windows appears to be 16336...
for (var i = 0; i < 17000; i++)
{
using (var response = client.Get("/accept"))
{
Assert.AreEqual(response.Body, "Body");
}
}
});
}
示例11: ShouldGETWithQueryParametersObject
public void ShouldGETWithQueryParametersObject()
{
using (FakeHttpServer server = new FakeHttpServer("http://localhost:8080/api/customers"))
{
var extractor = new RequestExtractor();
server.UseBodyExtractor(extractor);
server.Listen();
RestClient client = new RestClient();
var response = client.Get("http://localhost:8080/api/customers")
.WithQueryParameters(new { customerid = 123 })
.Execute();
Assert.AreEqual("123", extractor.QueryString["customerid"], "The ID was not passed.");
}
}
示例12: LotsOfRequests
public void LotsOfRequests()
{
var httpClient = new HttpClient();
Measure("Warm up!", () => MakeRequest(httpClient, _requestUri));
var reusedClient = new RestClient(BaseAddress);
Measure("Reused HttpClient", () => MakeRequest(httpClient, _requestUri) );
Measure("Reused RestClient", () => reusedClient.Get("/foo"));
Measure("HttpClient per request", () => MakeRequest(new HttpClient(), _requestUri));
Measure("RestClient per request", () => new RestClient(BaseAddress).Get("/foo"));
}
示例13: ShouldGET
public void ShouldGET()
{
using (FakeHttpServer server = new FakeHttpServer("http://localhost:8080/api/customers"))
{
server.StatusCode = HttpStatusCode.OK;
server.Listen();
RestClient client = new RestClient();
var response = client.Get("http://localhost:8080/api/customers").Execute();
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The wrong status code was returned.");
Assert.IsTrue(response.IsSuccessStatusCode, "A success code was returned. There should be no error.");
Assert.IsNull(response.Result, "No WHEN handler was defined. The result should be null.");
}
}
示例14: ShouldGETWithSimpleTemplate
public void ShouldGETWithSimpleTemplate()
{
using (FakeHttpServer server = new FakeHttpServer("http://localhost:8080/api/customers"))
{
var extractor = new RequestExtractor();
server.UseBodyExtractor(extractor);
server.Listen();
RestClient client = new RestClient();
var response = client.Get("http://localhost:8080/api/customers/{customerId}", new
{
customerId = 123
}).Execute();
Assert.IsTrue(extractor.Url.ToString().EndsWith("123"), "The ID was not passed.");
}
}
示例15: Main
static void Main()
{
var client = new RestClient("http://catfacts-api.appspot.com/api");
var response = client.Get<CatFactResponse>(
new RestRequest("facts")
.WithQueryParameter("number", 5)
);
Console.WriteLine("Retrieved " + response.Facts.Count + " cat facts.");
Console.WriteLine(response.Facts[0]);
Console.ReadKey();
QueryAsync().Wait();
}