我需要将sender
和238045366373
更改为变量字符串,以便可以在不同的时间采用不同的值
request.AddParameter("application/json", "{""messages"":[{""from"":""sender"",""to"":[""238045366373""],""text"":""May the God be with you Jolaoluwa!""}]}", ParameterType.RequestBody)
答案 0 :(得分:0)
如果您只发送一个号码,则可以使用此功能。
Private Function SendInfoBip(smsHeader As String, mobileNumber As String, message As String) As String
Dim client = New WebClient()
Dim message2 As String = HttpUtility.UrlEncode(message.Trim())
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322; .NET CLR 3.5.20404)")
client.QueryString.Add("user", "YOUR_USERNAME") 'Replace YOUR_USERNAME with your actual username
client.QueryString.Add("password", "YOUR_PASSWORD") 'Replace YOUR_PASSWORD with your actual password
client.QueryString.Add("GSM", mobileNumber)
client.QueryString.Add("SMSText", message2)
client.QueryString.Add("sender", smsHeader)
Dim baseurl As String = "http://api2.infobip.com/api/sendsms/plain"
Dim s As String = client.DownloadString(baseurl)
'Dim temp = s.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
'Dim flag As Boolean = Long.Parse(temp(0)) > 0
'Return flag
Return s
End Function
您需要做的就是致电SendInfoBip
,如下所示。
Dim sender = "Scartag"
Dim mobileNumber = "2348023061555"
Dim message = "My brand new message"
Dim result As Boolean = SendInfoBip(sender, mobileNumber, message)
'result now holds the value you want to output to the screen
<强>更新强>
如果您需要使用变量的正确方法而不是您提前请求的硬编码值,请参阅下文。
Dim header = "Sender"
Dim mobileNumber = "2348023061555"
Dim mobileNumber2 = "23480230619085"
Dim message = "Test message"
request.AddParameter("application/json", "{""messages"":[{""from"":""" + header + """,""to"":[""" + mobileNumber + """, """ + mobileNumber2 + """ ],""text"":""" + message + """}]}", ParameterType.RequestBody)