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.
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?
If the request wasn't successful, you'd get
a response back with IsSuccessful propertyset tofalse and the error explained in the
ErrorException and ErrorMessage properties.
Best Regards,
YihuiSun
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
53 Points
206 Posts
How to POST API via HTTP in C#
Mar 21, 2021 03:55 AM|Enzyme|LINK
I have Api I want to consume for sending SMS. The Api looks like below:
I tried puting the C# code as below, but it would not work, though it worked on Postman.
Please can anyone look into this code an advise my on the best way the resolve this issue.
All-Star
53711 Points
24035 Posts
Re: How to POST API via HTTP in C#
Mar 21, 2021 12:56 PM|mgebhard|LINK
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?
Member
53 Points
206 Posts
Re: How to POST API via HTTP in C#
Mar 21, 2021 06:24 PM|Enzyme|LINK
There is no error message, and it does not send the SMS.
All parameters are fixed in the URL.
All-Star
58464 Points
15788 Posts
Re: How to POST API via HTTP in C#
Mar 21, 2021 06:52 PM|bruce (sqlwork.com)|LINK
what is the response? it probably an html page that tells you what is wrong.
All-Star
53711 Points
24035 Posts
Re: How to POST API via HTTP in C#
Mar 21, 2021 08:00 PM|mgebhard|LINK
Can you explain what troubleshooting steps you have performed? Did you set a breakpoint and review the response?
Contributor
3040 Points
863 Posts
Re: How to POST API via HTTP in C#
Mar 22, 2021 05:57 AM|YihuiSun|LINK
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