。
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
UPDATE
如果需要使用變量,而不是硬編碼值的正確方法,你早要求見下文。
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)
我得到的錯誤消息是「編譯器錯誤消息:BC30516:重載解析失敗,因爲沒有可訪問的'AddParameter'接受這個參數數目。請幫忙 - – Pope
請通過導致問題的代碼...嘗試在變量字符串。 – scartag
request.AddParameter(「application/json」,「{」「messages」「:[{」「from」「:」&sender&「,」「to」「:[」&foneno&「],」「text」「: 「願上帝與你同在Jolaoluwa!」「}}}」,ParameterType.RequestBody) – Pope