Send SMS to Mobile using Way2SMS in C# and VB.Net

Last Reply 8 months ago By dharmendr

Posted 8 months ago

How to send sms using way2sms in windows application vb.net

I have tried with the below code but not successful. Please help

    Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
        Try 
            Dim mobile As String = "register no"
            Dim Password As String = "register pass"
			dim strGet as string
            Dim text As String = txtMessage.Text
            Dim number As String = txtPhoneno.Text
            Dim key As String = "key"
            Dim url As String = "https://smsapi.engineeringtgr.com/send/?Mobile=" + mobile + "&Password=" + Password + "&Key=" + key + "&Message=" + text + "&To=" + number + ""
             
            strGet = url + "apikey=" + key _
            + "&numbers=" + number _
            + "&message=" + WebUtility.UrlEncode(text)

            Dim webClient As New System.Net.WebClient
           Dim result As String = webClient.DownloadString(strGet)
            MessageBox.Show(result, "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

 

Posted 8 months ago Modified on 7 months ago

Hi nirmal90,

Using the API https://smsapi.engineeringtgr.com/

Step 1: Register on Way2SMS.

  1. Register on way2sms.com if not register.
  2. Goto http://way2sms.com and create an account. Therefore you got password on your mobile number. This mobile number and password use in the API.

Step 2: Generate API Key.

Step 3: Run API.

Refer below code.

Namespaces

C#

using System.IO;
using System.Net;

VB.Net

Imports System.IO
Imports System.Net

Code

C#

private void btnSend_Click(object sender, EventArgs e)
{
    string mobile = "Way2SMSMobileNo";
    string password = "Way2SMSPassword";
    string text = txtMessage.Text;
    string number = txtPhoneno.Text;
    string key = "API_Key";

    string url = "https://smsapi.engineeringtgr.com/send/?Mobile=" + mobile + "&Password=" + password + "&Message=" + text + "&To=" + number + "&Key=" + key;

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    ServicePointManager.DefaultConnectionLimit = 9999;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "GET";
    request.ContentType = "application/json";
    request.ContentLength = 0;

    try
    {
        WebResponse webResponse = request.GetResponse();
        Stream webStream = webResponse.GetResponseStream();
        StreamReader responseReader = new StreamReader(webStream);
        string response = responseReader.ReadToEnd();
        responseReader.Close();
    }
    catch (Exception ex)
    {

    }
}

VB.Net

Private Sub btnSend_Click(sender As System.Object, e As System.EventArgs) Handles btnSend.Click
    Dim mobile As String = "Way2SMSMobileNo"
    Dim password As String = "Way2SMSPassword"
    Dim text As String = txtMessage.Text
    Dim number As String = txtPhoneno.Text
    Dim key As String = "API_Key"

    Dim url As String = "https://smsapi.engineeringtgr.com/send/?Mobile=" & mobile & "&Password=" & password & "&Message=" & text & "&To=" & number & "&Key=" & key
    ServicePointManager.Expect100Continue = True
    ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
    ServicePointManager.DefaultConnectionLimit = 9999
    Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
    request.Method = "GET"
    request.ContentType = "application/json"
    request.ContentLength = 0

    Try
        Dim webResponse As WebResponse = request.GetResponse()
        Dim webStream As Stream = webResponse.GetResponseStream()
        Dim responseReader As StreamReader = New StreamReader(webStream)
        Dim response As String = responseReader.ReadToEnd()
        responseReader.Close()
    Catch ex As Exception
    End Try
End Sub

Note: Here you need to provide the Mobile Number. So do it at your own risk.