locked
How to POST API via HTTP in C# RRS feed

  • Question

  • User-218090889 posted

    I have Api I want to consume for sending SMS. The Api  looks like below:

     
    http://sms.bulksmsprovider.ng/api/?username=user&password=pass&message=test&sender=welcome&mobiles=2348030000000
     

    I tried puting the C# code as below, but it would not work, though it worked on Postman.

    var client = new RestClient("http://sms.bulksmsprovider.ng/api/?username=user&password=pass&message=test&sender=welcome&mobiles=2348030000000");
    var request = new RestRequest(Method.POST);
    IRestResponse response = client.Execute(request);

    Please can anyone look into this code an advise my on the best way the resolve this issue.

    Sunday, March 21, 2021 3:55 AM

Answers

  • User1686398519 posted

    Hi Enzyme, 

    IRestResponse response = client.Execute(request);

    You can check the value of response.

    If the request wasn't successful, you'd get a response back with IsSuccessful property set to false and the error explained in the ErrorException and ErrorMessage properties.

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 22, 2021 5:57 AM

All replies

  • User475983607 posted

    What does "not working" mean?  Are you receiving an error?  If so, what is the error?

    Sending a POST request is questionable since you are sending all the parameters in the URL.   This is usually a GET not a POST.  Are you sure you are following the sms.bulksmsprovider.ng documentation?

    RestClient is a 3rd party library.  Have you read the documentation to make sure you are using the library correcty?  Perhaps try using the HttpClient which comes with .NET?  

    Sunday, March 21, 2021 12:56 PM
  • User-218090889 posted

    What does "not working" mean?  Are you receiving an error?  If so, what is the error?

    There is no error message, and it does not send the SMS.
    All parameters are fixed in the URL.

    Sunday, March 21, 2021 6:24 PM
  • User-474980206 posted

    what is the response? it probably an html page that tells you what is wrong.

    Sunday, March 21, 2021 6:52 PM
  • User475983607 posted

    There is no error message, and it does not send the SMS.
    All parameters are fixed in the URL.

    Can you explain what troubleshooting steps you have performed?  Did you set a breakpoint and review the response?  

    Sunday, March 21, 2021 8:00 PM
  • User1686398519 posted

    Hi Enzyme, 

    IRestResponse response = client.Execute(request);

    You can check the value of response.

    If the request wasn't successful, you'd get a response back with IsSuccessful property set to false and the error explained in the ErrorException and ErrorMessage properties.

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 22, 2021 5:57 AM