RestRequest类在哪里?

时间:2013-01-24 17:52:08

标签: c# .net mailgun

the getting started of maingun API的C#标签中,我找到以下代码。

public static RestResponse SendSimpleMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "sergeyo@profista.com");
       request.AddParameter("to", "serobnic@mail.ru");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.Method = Method.POST;
       return client.Execute(request);
}

当我谷歌这个类的名字时,我在不同的上下文中找到了几个对这个类的引用。但是,我似乎无法在mailgun网站,谷歌或MSDN上的任何地方找到RestRequest类的完全限定名称来查找它的文档。

任何人都可以指出这个类定义在哪里?

3 个答案:

答案 0 :(得分:17)

代码看起来像使用RestSharp

答案 1 :(得分:0)

RestSharp可从NuGet获得。从那里安装。

答案 2 :(得分:-2)

我遇到了同样的问题。但是我发现如果你使用的是JAVA 8,你不需要任何外部的库,但这里提供的java就是我的代码示例。

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

public class EmailDAO {

public static Response sendNewPasswordMessage() {
Client client = ClientBuilder.newClient();
client.register(new BasicAuthenticator("api","yourkey"));

WebTarget target = client.target("https://api.mailgun.net/v2/your-domain/messages");

MultivaluedMap formData = new MultivaluedHashMap();
formData.add("from", "Test <postmaster@test.net>");
formData.add("to", "anyone@test.net");
formData.add("subject", "Hello world");
formData.add("html", "Hello world <br /> <br /> ");

Invocation invocation = target.request().buildPost(Entity.form(formData));
return invocation.invoke();
}

}

希望有所帮助。