Hi indradeo,
Use the Uri.EscapeDataString() function to send the message with special characters.
Namespaces
C#
using System.IO;
using System.Net;
VB.Net
Imports System.IO
Imports System.Net
Code
protected void Page_Load(object sender, EventArgs e)
{
string message = "$#%^&*()?/|";
Response.Write(sendSMS("+919999999999", Uri.EscapeDataString(message)));
}
static string sendSMS(string mobileNo, string messageTxt)
{
string SMSurl = "my gateway";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
return sr.ReadToEnd();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim message As String = "$#%^&*()?/|"
Response.Write(sendSMS("+919999999999", Uri.EscapeDataString(message)))
End Sub
Private Shared Function sendSMS(ByVal mobileNo As String, ByVal messageTxt As String) As String
Dim SMSurl As String = "my gateway"
Dim request As HttpWebRequest = CType(WebRequest.Create(SMSurl), HttpWebRequest)
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(response.GetResponseStream())
Return sr.ReadToEnd()
End Function
You will get the response as Json string like below.
{"messages":[{"to":"919999999999","status":{"groupId":1,"groupName":"PENDING","id":7,"name":"PENDING_ENROUTE","description":"Message sent to next instance"},"messageId":"9219721866693983716","smsCount":1}]}