Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21301

working with Winsock

$
0
0
i m making a software for my self which sends sms using simple http api's given by the provider

im loading the csv file which has my customer phone number data in vsflexgrid and then when i hit send button the winsock is triggered .

below is my code for that
Code:

Private Sub cmsSend_Click()
txtResponse.Text = ""
Dim eUrl As URL

Dim strMethod As String
Dim strData As String
Dim strPostData As String
Dim strHeaders As String

Dim strHTTP As String
Dim X As Integer

Dim user_name As String
Dim pwd As String
Dim sender_name As String
Dim sms_data As String

    user_name = Text2.Text
    pwd = Text3.Text
    sender_name = "infoin"
    sms_data = "username=" & user_name & "&" & "password=" & pwd & "&" & "sendername=" & sender_name & "&"
    strPostData = ""
    strHeaders = ""
    strMethod = "GET"
   
    'This sets the eUrl variable's parameters
    eUrl.Scheme = "http"
    eUrl.Host = "promo.bulksmsnvoice.com"
    eUrl.Port = 80
    eUrl.URI = "/SMSAPI.jsp"
   
    ' configure winsock
    Winsock1.Close
    Winsock1.Protocol = sckTCPProtocol
    Winsock1.RemoteHost = eUrl.Host
    Winsock1.RemotePort = eUrl.Port
    Winsock1.Connect
   
    'wait for a connection
    While Not blnConnected
        DoEvents
    Wend
           
    'Send SMS to each Cell No from the List
    For i = 1 To FG.Rows - 1
       
        strData = ""
        If Len(FG.TextMatrix(i, 1)) = 10 Then      'When Cell No is enterd and 91 is present before it
       
            strData = sms_data & "mobileno=" & "91" & URLEncode(FG.TextMatrix(i, 1)) & "&" & "message=" & URLEncode(Text1.Text)
       
            'URL encoded data is appended to the URI with a ?
            eUrl.URI = eUrl.URI & "?" & strData
            Debug.Print eUrl.URI
            'build the HTTP request in the form
            '
            '{REQ METHOD} URI HTTP/1.0
            'Host: {host}
            '{headers}
            '
            '{post data}
            strHTTP = strMethod & " " & eUrl.URI & " HTTP/1.0" & vbCrLf
            strHTTP = strHTTP & "Host: " & eUrl.Host & vbCrLf
            strHTTP = strHTTP & strHeaders
            strHTTP = strHTTP & vbCrLf
            strHTTP = strHTTP & strPostData
           
            'send the HTTP request
            Winsock1.SendData strHTTP
           
            lblStatus.Caption = "Sent : " & i & "/" & FG.Rows - 1
           
        End If
       
    Next i
           
       
End Sub

the above code is suppose to send sms to all the numbers in the csv file but to my surprise it sent sms to only 1st number in the csv file which is diplayed in the vsflexgrid..

so i did a debug.print and found that eUrl.URI is making url's which are displayed below

/SMSAPI.jsp?username=demo1&password=demo3211&sendername=infoin&mobileno=919594039909&message=dfs
/SMSAPI.jsp?username=demo1&password=demo3211&sendername=infoin&mobileno=919594039909&message=dfs?user name=demo1&password=demo3211&sendername=infoin&mobileno=918446169139&message=dfs
/SMSAPI.jsp?username=demo1&password=demo3211&sendername=infoin&mobileno=919594039909&message=dfs?user name=demo1&password=demo3211&sendername=infoin&mobileno=918446169139&message=dfs?username=demo1&pass word=demo3211&sendername=infoin&mobileno=919405498981&message=dfs

this is wrong. it is just putting the next url after the first one that is the reason its not sending messages to all numbers

i want eurl.uri to make urls like

/SMSAPI.jsp?username=demo1&password=demo3211&sendername=infoin&mobileno=919594039909&message=dfs
/SMSAPI.jsp?username=demo1&password=demo3211&sendername=infoin&mobileno=918446169139&message=dfs
/SMSAPI.jsp?username=demo1&password=demo3211&sendername=infoin&mobileno=919405498981&message=dfs

if the urls are made like above then only the messages will go to all numbers. or else it will go to the first number as the url made is right

can ne one help me

Viewing all articles
Browse latest Browse all 21301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>