18

在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 网站、google 或 MSDN 上的任何地方找到 RestRequest 类的完全限定名称以找到它的文档。

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

4

3 回答 3

25

该代码看起来像是使用RestSharp

于 2013-01-24T17:55:10.563 回答
2

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

于 2018-08-10T21:58:21.943 回答
-2

I run in the same issue. But I found out that if you are using JAVA 8 you don't needs any external librairy but just what java provide already here is my code example.

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();
}

}

Hopes it helps.

于 2015-03-16T02:57:16.430 回答