locked
How to sent sms using Web API RRS feed

  • Question

  • I m new to programming and writing my first desktop application using Visual Basic 2010 and .NET 4. My client is demanding to integrate

    automatic SMS sending feature to his customer when they do any transaction. Suppose a customer orders something to my client then

    immediately customer should get a confirmation massage with order no. , Delivery Date and other details related with his order.

     

    I have bought a sms package from mysmsmantra.com and all that they have given me is my ID and Password and Developers API

    and They have no .NET coding samples.

    Now the problem is that I have no idea how to use Developer API in my application.

    I will be very very very grateful to anybody who can give some working code samples to integrate those Developers API in my Desktop 

    Application. While giving any code sample please consider i m a Beginner.

     

    Developers API are given below :

    Bulk SMS API Documentation (Single/multiple SMS via HTTP) for website/software  integration

    Send SMS:


    http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=username&password
    =password&sendername=sender id&mobileno=919999999999&message=Hello


    Sent Report:
    http://bulksms.mysmsmantra.com:8080/WebSMS/sentreport.jsp?username=username&password=
    password&fromdate=DD-MM-YYYY&todate=DD-MM-YYYY

    Check Balance:
    http://bulksms.mysmsmantra.com:8080/WebSMS/balance.jsp?username=username&password=password

    Change Password:
    http://bulksms.mysmsmantra.com:8080/WebSMS/changepassword.jsp?username=username&
    password=password&newpassword=aaaa

     

    Above HTTP API Code are fully compatible with PHP , ASP , Dot Net,JSP-Java integration


    Rahul
    Tuesday, February 22, 2011 7:13 PM

Answers

  • The following uses a method to construct the string.   The exception handler will capture any errors and report fail and display a messagebox with exception message.

    As to more details about network, I would check out the following.

    My.Computer.Network Namespace

    http://msdn.microsoft.com/en-us/library/hxza5zbx(v=vs.80).aspx

    This should get you some of those items.

     

    Imports System.Net
    Imports System.IO
    
    Public Class Form1
      Const SenderName As String = "InterExp"
    
      Public Function getHTTP(ByVal szURL As String) As String
        Dim HttpRequest As HttpWebRequest
        Dim httpResponse As HttpWebResponse
        Dim BodtText As String = Nothing
        Dim Bytes As Int32
        Dim ResponseStream As Stream
        Dim RecvByte(Byte.MaxValue) As Byte
    
        HttpRequest = CType(WebRequest.Create(szURL), HttpWebRequest)
    
        httpResponse = CType(HttpRequest.GetResponse(), HttpWebResponse)
        ResponseStream = httpResponse.GetResponseStream
    
        Do While (True)
          Bytes = ResponseStream.Read(RecvByte, 0, RecvByte.Length)
          If Bytes <= 0 Then Exit Do
          BodtText += System.Text.Encoding.UTF8.GetString _
          (RecvByte, 0, Bytes)
    
        Loop
        Return BodtText
      End Function
    
      Private Sub btnSendSMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '//Get Send Details from TextBoxes and Call SendMessage method
        If My.Computer.Network.IsAvailable = True Then
          Try
            Me.Cursor = Cursors.WaitCursor
            LblResult.Text = SendMessage(TxtName.Text, TxtPassword.Text, SenderName, TxtMobile.Text, TxtMessage.Text)
          Catch ex As Exception
            LblResult.Text = "Send Failed"
            MessageBox.Show(ex.Message)
          Finally
            Me.Cursor = Cursors.Arrow
          End Try
        Else
          LblResult.Text = "Cannot send Network Is Unavailable."
        End If
        
      End Sub
    
      Function SendMessage(ByVal Username As String,
                 ByVal Password As String,
                 ByVal SenderName As String,
                 ByVal MobileNumber As String,
                 ByVal Message As String) As String
        '//Build the appropriate string 
        Dim MessageStringURL As String = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=" & USername & "&password=" & Password & "/?&sendername=" & SenderName & " &mobileno=" & MobileNumber & "&message=" & Message
        Return getHTTP(MessageStringURL.Trim)
      End Function
    End Class
    
    

     

    • Marked as answer by Rahul_Kr Thursday, March 3, 2011 11:02 AM
    Thursday, March 3, 2011 7:36 AM

All replies

  • I'd take a look at the following class:

    http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx

     

    It shows how to send a web request and get a response from server.

    The URL they are showing in these looks to be what you would need to change to pass across the details you wish to send.

    I'd modified the example to

    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Text
    
    Module Moduel1
      Sub main()
    
        ' Create a request for the URL. 		
        Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/default.html")
    
    
        Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
    
        ' Display the status.
        Console.WriteLine(response.StatusDescription)
    
        ' Get the stream containing content returned by the server.
        Dim dataStream As Stream = response.GetResponseStream()
        ' Open the stream using a StreamReader for easy access.
        Dim reader As New StreamReader(dataStream)
        ' Read the content.
        Dim responseFromServer As String = reader.ReadToEnd()
        ' Display the content.
        Console.WriteLine(responseFromServer)
        ' Cleanup the streams and the response.
        reader.Close()
        dataStream.Close()
    
        response.Close()
      End Sub 'Main
    End Module
    
    
    • Proposed as answer by Calvin_GaoModerator Monday, February 28, 2011 5:11 AM
    • Marked as answer by Calvin_GaoModerator Wednesday, March 2, 2011 3:07 AM
    • Unmarked as answer by Rahul_Kr Wednesday, March 2, 2011 8:13 AM
    • Marked as answer by Rahul_Kr Wednesday, March 2, 2011 8:15 AM
    • Unmarked as answer by Rahul_Kr Wednesday, March 2, 2011 8:16 AM
    Tuesday, February 22, 2011 7:59 PM
  • Hi dmr_ghy,

     

    Thanks for your post.

     

    How about the issue on your side? Dose the information provided by Spotty helpful?

     

    In addition, you can refer my reply in the following thread about how to send SMS:

    http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/fe514b16-08cf-47d0-a2f5-0b4c11ce847f

     

    I hope this will helpful, and I look forward to hearing from you soon.

     

    Best Regards,


    Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Calvin_GaoModerator Wednesday, March 2, 2011 3:07 AM
    • Unmarked as answer by Rahul_Kr Wednesday, March 2, 2011 8:13 AM
    Monday, February 28, 2011 5:11 AM
    Moderator
  • Thanks a lot Spotty and Calvin-MFST,  May be sample codes given by you are usefull but i m not able to use it. I m just a student and learning

    visual basic 2010. Can anybody give me name of a book which have good explanation about sending SMS and e-mails using visual basic 2010

    Thanks in advance.


    Rahul
    Tuesday, March 1, 2011 3:22 AM
  • Hi dmr_ghy,

     

    Maybe you can search some books from google. I started learning .NET framework from the MSDN library :-)

     

    In addition, you can refer to the following documents for some more details:

    How to Send and Receive SMS with the Orange SMS API

    Frequently Asked Questions for System.Net.Mail

     

    I hope this helps.

     

    Best Regards,


    Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 1, 2011 3:36 AM
    Moderator
  • I have tried a lot to search a book which has good discussion about sending SMS  through vb2010 application.

    I have tried in Google,Bing, Google Books etc. but couldn't find any book which can teach me how to sent sms through WEB API

    using VB2010.

    Thanks in advance.


    Rahul
    Tuesday, March 1, 2011 11:01 AM
  •  

    I doubt your going to find a book specific to SMS through VB2010 (Its just too specific and your really wanting to use a specific vendor's package)

    If it were me -I would look specifically at using the System.Web namespace functions and contact the vendor ( sms package from mysmsmantra.com ) to determine how to use their API's.

    Even if they provide simple examples - in VB (or C# you can feed it through code converter to get VB Code)

    This is probably quickest route to get up and running quickly.

    The API simply look like you are required to send URL with containing information, and then get the response.  (Hence the simple sample shows sending request, getting response)

     

    Wednesday, March 2, 2011 12:53 AM
  • Thanks a lot spotty for your syggestion,

    I hv already purchased a sms package from mysmsmantra.com.

    I requested a code sample in vb.net but they gave me ASP code sample and said this is all they have.

    will you please post a complete code example to use mysmsmantra API

    Thanks in advance


    Rahul
    Wednesday, March 2, 2011 8:12 AM
  • Post up what they have sent and then it can be converted to .net

    I don't use the API, so it would be a straight conversion of there sample.

    Wednesday, March 2, 2011 4:14 PM
  • Below is ASP codes sent by mysmsmantra.com :

    <html>
    <head>
    <title>MySmsMantra</title>
    </head>
    <body>
    <%@language = "VBScript" %>

    <%
    usersms=Request.QueryString("username")
    passsms=Request.QueryString("password")
    sender=Request.QueryString("sender")
    sendto=right(TRIM(Request.QueryString("mobile")),10)
    message=Server.URLEncode(Request.QueryString("message"))
           
    if usersms <> "" And passsms <> "" and len(sendto)=10 then

        Set GetConnection = CreateObject("Microsoft.XMLHTTP")
        GotothisURL = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username="&usersms&"&password="&passsms&"&sendername="&sender&"&mobileno="&sendto&"&message="&message""
        'Conect to specified URL
        response.write gotothisurl   
     
        GetConnection.Open "get", GotothisURL, False
        GetConnection.Send 
        response.write getconnection.responseText
       
    End if
    %>
    </body>
    </html>

     

    I don't know how to use above codes but i managed to sent sms successfully using mysmsmantra.com API

    I got these codes from this book : Network Programming in .NET With C# and Visual Basic : http://www.amazon.com/Network-programming-NET-Visual-Basic/dp/1555583156

    I m giving the codes below :

     Public Function getHTTP(ByVal szURL As String) As String
            Dim HttpRequest As HttpWebRequest
            Dim httpResponse As HttpWebResponse
            Dim BodtText As String = Nothing
            Dim Bytes As Int32
            Dim ResponseStream As Stream
            Dim RecvByte(Byte.MaxValue) As Byte

            HttpRequest = CType(WebRequest.Create(szURL), HttpWebRequest)

            httpResponse = CType(HttpRequest.GetResponse(), HttpWebResponse)
            ResponseStream = httpResponse.GetResponseStream

            Do While (True)
                Bytes = ResponseStream.Read(RecvByte, 0, RecvByte.Length)
                If Bytes <= 0 Then Exit Do
                BodtText += System.Text.Encoding.UTF8.GetString _
                (RecvByte, 0, Bytes)

            Loop
            Return BodtText
        End Function

    Private Sub btnSendSMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendSMS.Click
            Try
                Me.Cursor = Cursors.WaitCursor
                Dim ABC As String = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=InterLtd&password=azman2531986/?&sendername=InterExp&mobileno=919774281149&message=" & txtURL.Text.Trim

               txtResult.Text = getHTTP(ABC.Trim)
                Me.Cursor = Cursors.Arrow
            Catch ed As WebException
                MsgBox(ed.Message)
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                Me.Cursor = Cursors.Arrow
            End Try

        End Sub

     

    Can you help me to make above mention codes more robust that it can handle more exceptions and show specific message

    about exception to users. How to get the state of internet connection and also connection quality and descriptions like IP Address,

    Connection speed etc. I want to make my application more real world application.

    At last i would like to thank you spotty for your continuous support.You have inspired me to contribute to the community.

    I also want to help others in the community in whatever way i can. can you please tell me details how you got my post or

    any other post which is unanswered or can be answered by me. This is my first interaction with MSDN community so i

    know nothing. Thank you very much.

     

     

     

     

     


    Rahul
    Thursday, March 3, 2011 3:14 AM
  • The following uses a method to construct the string.   The exception handler will capture any errors and report fail and display a messagebox with exception message.

    As to more details about network, I would check out the following.

    My.Computer.Network Namespace

    http://msdn.microsoft.com/en-us/library/hxza5zbx(v=vs.80).aspx

    This should get you some of those items.

     

    Imports System.Net
    Imports System.IO
    
    Public Class Form1
      Const SenderName As String = "InterExp"
    
      Public Function getHTTP(ByVal szURL As String) As String
        Dim HttpRequest As HttpWebRequest
        Dim httpResponse As HttpWebResponse
        Dim BodtText As String = Nothing
        Dim Bytes As Int32
        Dim ResponseStream As Stream
        Dim RecvByte(Byte.MaxValue) As Byte
    
        HttpRequest = CType(WebRequest.Create(szURL), HttpWebRequest)
    
        httpResponse = CType(HttpRequest.GetResponse(), HttpWebResponse)
        ResponseStream = httpResponse.GetResponseStream
    
        Do While (True)
          Bytes = ResponseStream.Read(RecvByte, 0, RecvByte.Length)
          If Bytes <= 0 Then Exit Do
          BodtText += System.Text.Encoding.UTF8.GetString _
          (RecvByte, 0, Bytes)
    
        Loop
        Return BodtText
      End Function
    
      Private Sub btnSendSMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '//Get Send Details from TextBoxes and Call SendMessage method
        If My.Computer.Network.IsAvailable = True Then
          Try
            Me.Cursor = Cursors.WaitCursor
            LblResult.Text = SendMessage(TxtName.Text, TxtPassword.Text, SenderName, TxtMobile.Text, TxtMessage.Text)
          Catch ex As Exception
            LblResult.Text = "Send Failed"
            MessageBox.Show(ex.Message)
          Finally
            Me.Cursor = Cursors.Arrow
          End Try
        Else
          LblResult.Text = "Cannot send Network Is Unavailable."
        End If
        
      End Sub
    
      Function SendMessage(ByVal Username As String,
                 ByVal Password As String,
                 ByVal SenderName As String,
                 ByVal MobileNumber As String,
                 ByVal Message As String) As String
        '//Build the appropriate string 
        Dim MessageStringURL As String = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=" & USername & "&password=" & Password & "/?&sendername=" & SenderName & " &mobileno=" & MobileNumber & "&message=" & Message
        Return getHTTP(MessageStringURL.Trim)
      End Function
    End Class
    
    

     

    • Marked as answer by Rahul_Kr Thursday, March 3, 2011 11:02 AM
    Thursday, March 3, 2011 7:36 AM
  • Thanks a lot spotty.

    You have inspired me to contribute to the community.

    I also want to help others in the community in whatever way i can. can you please tell me details how you got my post or

    any other post which is unanswered or can be answered by me. This is my first interaction with MSDN community so i

    know nothing. Thank you very much.


    Rahul
    Thursday, March 3, 2011 11:03 AM
  • I'm glad the we inspire people in the forums.

    Personally - I check back on the forums and scan through titles that are interesting.  Looking at what people are wanting to do and many are common simple tasks.

    Often the issue is finding out what they want as the intial explanations don't give enough of the right information.   But we can point people in the correct direction to find the right information.

    The forums are community so there are areas where I may not have direct expertise of an API but can find the examples (play with them a bit) and provide a solution.   This broadens my knowledge at the same time.    The more you play with your SMS code and get this working well I'm sure you can contibute as other ask similar questions about VB and SMS.

    My best advise would be to keep scanning the forums - looking at code and this will help you learn a lot more about achieving things using VB.

    Thursday, March 3, 2011 4:29 PM