public String convertStringToHex(String str)
{
char[] chars = str.toCharArray();
StringBuffer hex = new StringBuffer();
String temp;
for(int i = 0; i < chars.length; i++)
{
temp="00"+Integer.toHexString((int)chars[i]);
temp = new StringBuffer(temp).reverse().toString();
temp=temp.substring(0,4);
temp = new StringBuffer(temp).reverse().toString();
hex.append(temp);
}
return hex.toString();
}
using Microsoft.VisualBasic;
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Configuration;
using System.Data;
using System.Web;
public class SMSCAPI
{
private WebProxy objProxy1 = null;
public string SendSMS()
{
string User = "xxxxx";
string password = "xxxxx";
string Mobile_Number = "91xxxxxxxxxx";
string Message = "";
String mtype = "OL";
string stringpost = null;
Message = convertHexa("Enter Your Language SMS");
stringpost = "User=" + User + "&passwd=" + password + "&mobilenumber=" + Mobile_Number
+ "&message=" + Message + "&mtype=" + mtype + "&DR=Y";
HttpWebRequest objWebRequest = null;
HttpWebResponse objWebResponse = null;
StreamWriter objStreamWriter = null;
StreamReader objStreamReader = null;
try
{
//if ((objProxy1 != null))
//{
// objWebRequest.Proxy = objProxy1;
//}
//WebProxy myProxy = new WebProxy("YOUR PROXY", PROXPORT);
//myProxy.BypassProxyOnLocal = true;
//wrGETURL.Proxy = myProxy;
string stringResult = null;
objWebRequest = (HttpWebRequest)WebRequest.Create("http://smscountry.com/smscwebservice_bulk.aspx");
objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objStreamWriter = new StreamWriter(objWebRequest.GetRequestStream());
objStreamWriter.Write(stringpost);
objStreamWriter.Flush();
objStreamWriter.Close();
objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
objStreamReader = new StreamReader(objWebResponse.GetResponseStream());
stringResult = objStreamReader.ReadToEnd();
objStreamReader.Close();
return stringResult;
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
if ((objStreamWriter != null))
{
objStreamWriter.Close();
}
if ((objStreamReader != null))
{
objStreamReader.Close();
}
objWebRequest = null;
objWebResponse = null;
objProxy1 = null;
}
}
public String convertHexa( String strmsg)
{
string strmsg1 = "";
char[] chrs = strmsg.ToCharArray();
for (long i = 0; i <= chrs.Length - 1; i++)
{
strmsg1 = strmsg1 + ("0000" + Convert.ToInt32(chrs[i]).ToString("X")).Substring(("0000"
+ Convert.ToInt32(chrs[i]).ToString("X")).Length - 4, 4);
}
return strmsg1 ;
}
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
Dim hexa_string As String, result As String
hexa_string = convertHexa("????? ?????")
result = SendSMS("XXXX", "XXXX", "XXXX", hexa_string, "SMSCNT", "OL", "Y")
Response.Write(result)
End Sub
Public Function SendSMS(ByVal User As String, ByVal password As String, ByVal Mobile_Number
As String, ByVal Message As String, Optional ByVal SID As String = "SMSCntry", Optional
ByVal MType As String = "N", Optional ByVal DR As String = "N") As String
Dim stringpost As System.Object = "User=" & User & "&passwd=" & password & "&mobilenumber="
& Mobile_Number & "&message=" & Message & "&SID=" & SID & "&MTYPE=" & MType & "&DR="
& DR
Dim functionReturnValue As String = Nothing
functionReturnValue = ""
Dim objWebRequest As HttpWebRequest = Nothing
Dim objWebResponse As HttpWebResponse = Nothing
Dim objStreamWriter As StreamWriter = Nothing
Dim objStreamReader As StreamReader = Nothing
Try
Dim stringResult As String = Nothing
objWebRequest = DirectCast(WebRequest.Create("http://www.smscountry.com/SMSCwebservice.asp?"),
HttpWebRequest)
objWebRequest.Method = "POST"
'If (objProxy1 IsNot Nothing) Then
' objWebRequest.Proxy = objProxy1
'End If
' Use below code if you want to SETUP PROXY.
'Parameters to pass: 1. ProxyAddress 2. Port
'You can find both the parameters in Connection settings of your internet explorer.
'Dim myProxy As New WebProxy("YOUR PROXY", PROXPORT)
'myProxy.BypassProxyOnLocal = True
'wrGETURL.Proxy = myProxy
objWebRequest.ContentType = "application/x-www-form-urlencoded"
objStreamWriter = New StreamWriter(objWebRequest.GetRequestStream())
objStreamWriter.Write(stringpost)
objStreamWriter.Flush()
objStreamWriter.Close()
objWebResponse = DirectCast(objWebRequest.GetResponse(), HttpWebResponse)
objStreamReader = New StreamReader(objWebResponse.GetResponseStream())
stringResult = objStreamReader.ReadToEnd()
objStreamReader.Close()
Return (stringResult)
Catch ex As Exception
Return (ex.Message)
Finally
If (objStreamWriter IsNot Nothing) Then
objStreamWriter.Close()
End If
If (objStreamReader IsNot Nothing) Then
objStreamReader.Close()
End If
objWebRequest = Nothing
objWebResponse = Nothing
'objProxy1 = Nothing
End Try
End Function
Public Function convertHexa(ByVal strmsg As String) As String
Dim strmsg1 As String = Nothing
Dim is_language As Short = 0
Dim chrs() As Char = strmsg.ToCharArray
For i As Long = 0 To chrs.Length - 1
strmsg1 = strmsg1 & ("0000" & Hex(AscW(chrs(i)))).Substring(("0000" & Hex(AscW(chrs(i)))).Length
- 4, 4)
Next
Return strmsg1
End Function