如何从RestSharp中处理RestClient

时间:2017-12-22 11:44:00

标签: .net restsharp

您好我正在使用RestSharp nuget包中的RestClient,但我发现它没有实现IDisposable。所以我需要处理它或如何处置它?

示例代码来自Mailgun api:

RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.Resource = "{domain}/messages.mime";
        request.AddParameter ("to", "bar@example.com");
        request.AddFile ("message", Path.Combine ("files", "message.mime"));
        request.Method = Method.POST;
        return client.Execute (request);

0 个答案:

没有答案