locked
Need help changing RestSharp to HttpClient RRS feed

  • Question

  • Hi,

    I have below code using RestSharp but it's not working on my project due to compatibility issues.

    I want to ask how can I change the same to work with HttpClient?

    RestClient client = new RestClient();
    client.BaseUrl = new Uri("https://api.mailgun.net/v3");
    client.Authenticator = new HttpBasicAuthenticator("api", "key-fbd876ed51232f347042d0009d9xxxxxx");
    RestRequest request = new RestRequest();
    request.AddParameter("domain", "domain.softnames.com", ParameterType.UrlSegment);
    request.Resource = "{domain}/messages";
    request.AddParameter("from", "Excited User <noreply@softnames.com>");
    request.AddParameter("to", "uk@softnames.com");
    request.AddParameter("subject", "Hello");
    request.AddParameter("text", "Testing some Mailgun awesomness! This is all about the text only. Just testing the text of this email.");
    request.Method = Method.POST;
    client.Execute(request);


    Thanks,

    Jassim


    Friday, November 3, 2017 3:00 PM

All replies

  • Hi Jassim RAahma,

    Thank you for posting here.

    If you want to make REST request using c# like HttpClient, you could refer to the following link.

    https://www.codeproject.com/Tips/497123/How-to-make-REST-requests-with-Csharp

    https://github.com/restsharp/RestSharp

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Monday, November 6, 2017 8:18 AM
  • Hi Jassim Rahma,

    Have you solved your problem?

    If you solved your problem, please mark the useful reply as answer. This will make answer searching in the forum and be beneficial to community members as well.

    If you have something else about this issue, please feel free to contact us.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, November 16, 2017 3:31 PM