A
A
Alexey Lebedev2015-11-16 10:41:57
ASP.NET
Alexey Lebedev, 2015-11-16 10:41:57

C# Is it possible to do without a library?

public static IRestResponse SendSimpleMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = new Uri("https://api.mailgun.net/v3");
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-11111111");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "legends-game.ru", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <[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);
}

You can do something like this without a library:
WebRequest request = WebRequest.Create("https://api.mailgun.net/v3");
            request.Method = "GET";
       request.AddParameter("from", "Excited User <[email protected]>");
       request.AddParameter("to", "[email protected]");

            WebResponse response = request.GetResponse();
            response.Close();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dasha Tsiklauri, 2015-11-16
@dasha_programmist

.net 4.5+:

using(var client = new HttpClient()){
  await client.GetAsync();
}

A
Andrey Danilov, 2015-11-16
@Danand

Can.
Light up the WebRequest class .
By the way, there was a similar question recently .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question