0

I am trying to send an sms from my website.

Below is the HTTP api which works perfectly.It sends the msg and returns the string

http://sms.mywebsite.com/api/sendmsg.php?user=MYID&pass=MYPASS&sender=SENDERID&phone=1234567980&text=Test Message&priority=ndnd&stype=normal

But i want to use it in C#.Accept mobile number from TextBox1 and Message from TextBox2

 WebRequest webRequest = WebRequest.Create("http://sms.mywebsite.com/api/sendmsg.php?user=MYID&pass=MYPASS&sender=SENDERID&phone=" + TextBox1.Text + "&text=" + TextBox2.Text+ "&priority=ndnd&stype=normal")

The first statement is executing if i paste the http code directly in the website and i recieve the smsin my mobile .But the WebRequest statement dosent send the sms

 TextBox1.Text=123456789;//some mobile number

 TextBox2.Text="Thankyou for registering @ MyWEBSITE. A verification email has been sent to Your email";
6
  • Which quotes do you mean? Please clarify your question and supply more code! Commented May 13, 2017 at 9:37
  • 1
    what is the error/problem you're facing? Commented May 13, 2017 at 9:38
  • the fist line of code is executing if i paste the link in the browser.I recieve a msg. Commented May 13, 2017 at 9:41
  • But the second line dosent send a msg but it executes Commented May 13, 2017 at 9:42
  • @Melwin can you please add the whole part where you use this Commented May 13, 2017 at 9:42

2 Answers 2

1

You seem to be only creating a web request object and not executing it.

var response = webRequest.GetResponse();

Refer to the documentation @ https://msdn.microsoft.com/en-us/library/bw00b1dc(v=vs.110).aspx
I would also recommend you use a HttpClient instead.

Sign up to request clarification or add additional context in comments.

Comments

1

You should use Server.UrlEncode. Probably, you have some spaces and special characters in the text message.

WebRequest webRequest = WebRequest.Create(Server.UrlEncode("http://sms.mywebsite.com/api/sendmsg.php?user=MYID&pass=MYPASS&sender=SENDERID&phone=" + TextBox1.Text + "&text=" + TextBox2.Text+ "&priority=ndnd&stype=normal"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.