C# RestRequest 类在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14507601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the RestRequest class?
提问by Samuel Rossille
In the C# tab of the getting started of maingun API, I find the following code.
在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 <[email protected]>");
request.AddParameter("to", "[email protected]");
request.AddParameter("to", "[email protected]");
request.AddParameter("subject", "Hello");
request.AddParameter("text", "Testing some Mailgun awesomness!");
request.Method = Method.POST;
return client.Execute(request);
}
When I google the name of the class, I find several reference to this class in different contexts. However, I can't seem to find the fully qualified name of the RestRequest class anywhere on the mailgun website, google or MSDN to find it's documentation.
当我用谷歌搜索类的名称时,我发现在不同的上下文中有几个对这个类的引用。但是,我似乎无法在 mailgun 网站、谷歌或 MSDN 上的任何地方找到 RestRequest 类的完全限定名称来查找它的文档。
Anybody can point out where is this class defined ?
任何人都可以指出这个类是在哪里定义的?
回答by Mickael Dubois
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.
我遇到了同样的问题。但我发现,如果您使用的是 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 <[email protected]>");
formData.add("to", "[email protected]");
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.
希望它有帮助。
回答by mcolegro
RestSharp is available from NuGet. Install it from there.
RestSharp 可从 NuGet 获得。从那里安装它。