EVB WINSOCK PROBLEM

Hi experts,
i want to ask about how to fix this trouble,

i have source for winsock sample like this

Private Sub Command16_Click()
                    WinSock1.RemoteHost = "smserver.com"
                    WinSock1.RemotePort = "80"
                    Winsock1.Connect
end sub

Private Sub WinSock1_Connect()
Dim strWebPage As String
Dim strCommand As String

    strWebPage = "www.smsserver.com/send.php?api_login=" & Text4.Text & "&api_password=" & Text14.Text & _
    "&action=sms_interface" & "&recipient=" & Text2.Text & "&sender=" & Text10.Text & _
    "&msg=" & Text9.Text
    strCommand = "GET " & strWebPage & " HTTP/1.0" & vbCrLf
    strCommand = strCommand & "Accept: */*" & vbCrLf
    strCommand = strCommand & "Accept: text/html" & vbCrLf
    strCommand = strCommand & vbCrLf
    WinSock1.SendData strCommand
    End If
end sub

Private Sub WinSock1_DataArrival(ByVal bytesTotal As Long)
Dim sData As String
WinSock1.GetData sData
MsgBox sData
end sub

The problem is if i send long SMS like,
"hi, how are you? how is mom, father, sister, and others? hope everything... ok?!"
in the text9 textbox which is for all the sms text being typed, the sData response is "400 Bad Request"
but if i send SMS something like,
"hi, this is only test"
there sms send successfully!

Why is it like this? please give me solution from the source above

Thanks.
abangbataxAsked:
Who is Participating?
 
BrianGEFF719Commented:
Hello abangbatax,

The reason you are getting this response from the server is that it does not understand your request. The data you are sending contains spaces. You need to escape the charecter sequence. However, a simple replace() should work just fine since the only problem is the space....So here is a modified connect function and an escape() function incase you want it:


Private Sub WinSock1_Connect()
Dim strWebPage As String
Dim strCommand As String

    strWebPage = "www.smsserver.com/send.php?api_login=" & Text4.Text & "&api_password=" & Text14.Text & _
    "&action=sms_interface" & "&recipient=" & Text2.Text & "&sender=" & Text10.Text & _
    "&msg=" & replace(Text9.Text," ","%20")
    strCommand = "GET " & strWebPage & " HTTP/1.0" & vbCrLf
    strCommand = strCommand & "Accept: */*" & vbCrLf
    strCommand = strCommand & "Accept: text/html" & vbCrLf
    strCommand = strCommand & vbCrLf
    WinSock1.SendData strCommand
    End If
end sub





Public Function Escape(ByVal strString As String) As String
Dim iCount As Integer
Dim retString As String

For iCount = 1 To Len(strString)
    retString = retString & "%" & IIf(Len(Hex(Asc(Mid(strString, iCount, 1)))) < 2, Hex(Asc(Mid(strString, iCount, 1))) & "0", Hex(Asc(Mid(strString, iCount, 1))))
Next iCount
Escape = retString

End Function
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.