I tried to send sms
it was using textlocal.in
this is the code i tried
Public Function SendSms(sender As Object, e As EventArgs) Handles Button1.Click
Dim apikey = txtAPI.Text
Dim message = txtMsg.Text
Dim numbers = txtNum.Text
Dim strPOST As String
Dim senderName = txtSend.Text
Dim url As String = "https://api.textlocal.in/send/?"
strPOST = url + "apikey=" + apikey _
+ "&numbers=" + numbers _
+ "&message=" + WebUtility.UrlEncode(message) _
+ "&sender=" + sender
Dim request As WebRequest = WebRequest.Create(strPOST)
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strPOST)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
Console.ReadLine()
reader.Close()
dataStream.Close()
response.Close()
If responseFromServer.Length > 0 Then
Return responseFromServer
Else
Return CType(response, HttpWebResponse).StatusDescription
End If
End Function
it is saying Operator '+' is not defined for string " https://api.textlocal.in/send/?a " and type 'Button
In this code sender
is the Button that raises the event:
Public Function SendSms(sender As Object
^^^^^^
It is not the phone number of the person sending the message. Replace sender
with senderName
on this line:
strPOST = url + "apikey=" + apikey _
+ "&numbers=" + numbers _
+ "&message=" + WebUtility.UrlEncode(message) _
+ "&sender=" + sender
^^^^^^^
Do not use +
to concatenate strings in vb unless you know exactly what it is doing
Use &
to concatenate strings, but in this case I would recommend you use string formatting
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.