Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Please check my code and correct it

Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Partial Class picturesms
    Inherits System.Web.UI.Page
    Dim objProxy As WebProxy = Nothing

    Private Function convertToHex(ByVal str1 As String) As String
        Dim strRetVal As String = "", i As Integer = 0
        Try
            For i = 1 To Len(str1)
                strRetVal = strRetVal & Right("00" & Hex(Asc(Mid(str1, i, 1))), 2)
                Response.Write(strRetVal)
                'Response.End()
            Next
            convertToHex = strRetVal
        Catch ex As Exception
            convertToHex = Right("00" & Hex(Asc("S")), 2)
        End Try
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim strPostBody As String
        Dim strPostResponse As String = ""
        Dim strRnd As String = ""
        Dim strText As String = Trim("" & Request.QueryString("TEXT"))
        'response.write("strText")
        Dim userName As String = Request.QueryString("user") 'Enter Your User Name
        Dim password As String = Request.QueryString("passwd") 'Enter Your Password
        Dim mobileNumber As String = Request.QueryString("mobilenumber") 'Enter Multiple Mobile Numbers With Comma Seperated'
        Dim message As String = Request.QueryString("message") 'Enter Your Message
        Dim senderid As String = Request.QueryString("sid") ' Enter Your Senderid
        Dim messageType As String = Request.QueryString("mtype") ' Enter Your Message Type As N for Normal Message, O for Other Laungauge Sms
        'Dim deliveryReports As Char = Request.QueryString("DR") ' if U want To Know Delivery Reports Enter Y it Gives JOBID Otherwise N 
        Dim deliveryReports As Char = "Y" ' if U want To Know Delivery Reports Enter Y it Gives JOBID Otherwise N 
        'response.write(Hex(Math.Round(Rnd() * 255, 0)))
        strRnd = Right("00" & Hex(Math.Round(Rnd() * 255, 0)), 2)
        'response.write(strRnd)
        'response.end()
        Dim bin As String = ""
        messageType = "L"
        If strText = "" Then
            message = "30000000020100" & message
        Else
            message = "300000" & Right("00" & Hex(Len(strText)), 2) & convertToHex(strText) & "020100" & message
            response.write(message)
        End If

        Dim segMentLength As Byte = message.Length \ 256
        If segMentLength Mod 256 > 0 Then
            segMentLength = segMentLength + 1
        End If
        Dim j As Int32 = 1
        Dim message1 As String
        For i As Int16 = 1 To segMentLength

            message1 = Mid(message, j, 256)
            j = j + 256
            bin = "0B0003" & strRnd & Right("00" & segMentLength, 2) & Right("00" & i, 2) & "0504158A0000"
            response.write(bin)

            strPostBody = "User=" & userName & "&passwd=" & password & "&mobilenumber=" & mobileNumber & "&binmess=" & bin & "&message=" & message1 & "&sid=" & senderid & "&mtype=" & messageType & "&DR=" & deliveryReports
            If i = 1 Then
                strPostResponse = sendSMS(strPostBody)
            Else
                strPostResponse = strPostResponse & "," & sendSMS(strPostBody)
            End If

        Next

        'Dim message1 As String = Mid(message, 257, 256)
        'Dim message2 As String = Mid(message, 257 + 256, 256)

        'message = Mid(message, 1, 256)

        'bin = "0B0003" & strRnd & "03010504158A0000"
        'strPostBody = "User=" & userName & "&passwd=" & password & "&mobilenumber=" & mobileNumber & "&binmess=" & bin & "&message=" & message & "&sid=" & senderid & "&mtype=" & messageType & "&DR=" & deliveryReports
        'strPostResponse = sendSMS(strPostBody)

        'bin = "0B0003" & strRnd & "03020504158A0000"
        'strPostBody = "User=" & userName & "&passwd=" & password & "&mobilenumber=" & mobileNumber & "&binmess=" & bin & "&message=" & message1 & "&sid=" & senderid & "&mtype=" & messageType & "&DR=" & deliveryReports
        'strPostResponse = strPostResponse & "," & sendSMS(strPostBody)

        'bin = "0B0003" & strRnd & "03030504158A0000"
        'strPostBody = "User=" & userName & "&passwd=" & password & "&mobilenumber=" & mobileNumber & "&binmess=" & bin & "&message=" & message2 & "&sid=" & senderid & "&mtype=" & messageType & "&DR=" & deliveryReports
        'strPostResponse = strPostResponse & "," & sendSMS(strPostBody)

        Response.Write(strPostResponse)

    End Sub
    Function sendSMS(ByVal stringPost As String) As String
     
        sendSMS = ""

        Dim objWebRequest As HttpWebRequest = Nothing
        Dim objWebResponse As HttpWebResponse
        Dim objStreamWriter As StreamWriter = Nothing
        Dim objStreamReader As StreamReader = Nothing
        Try

            Dim stringResult As String
            'objWebRequest = CType(WebRequest.Create("http://www.smscountry.com/smscwebservice.asp"), HttpWebRequest)
            


            objWebRequest.ContentLength = stringPost.Length
            objWebRequest.ContentType = "application/x-www-form-urlencoded"
            objStreamWriter = New StreamWriter(objWebRequest.GetRequestStream())
            objStreamWriter.Write(stringPost)
            objStreamWriter.Flush()
            objStreamWriter.Close()
            objWebResponse = CType(objWebRequest.GetResponse(), HttpWebResponse)
            objStreamReader = New StreamReader(objWebResponse.GetResponseStream())
            stringResult = objStreamReader.ReadToEnd()
            objStreamReader.Close()
            'Getting Response
            Return (stringResult)  'jobid
        Catch ex As Exception
            Return (ex.ToString)
        Finally
            If Not objStreamWriter Is Nothing Then
                objStreamWriter.Close()
            End If
            If Not objStreamReader Is Nothing Then
                objStreamReader.Close()
            End If
            objWebRequest = Nothing
            objWebResponse = Nothing
            objProxy = Nothing
        End Try

    End Function



End Class


[edit]Subject, tags, codeblock, moved the "question" out of the subject and into the body, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 30-Mar-11 21:10pm
v2
Comments
OriginalGriff 31-Mar-11 3:13am    
Now that I've formatted it a bit better, it's your turn to help us: Edit the question, take out the code dump and post just the relevant bits.

Then tell us what problem you are having - "It doesn't work" is not good enough - and try to point us in the right direction!
Keith Barrow 31-Mar-11 10:57am    
Very poor question, you have not said what (if anything) is wrong.
walterhevedeich 7-Apr-11 23:00pm    
If its a homework, better ask your instructor to check it. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900