2016-01-13 6 views
1

我需要的sender238045366373更改爲變量字符串,使得可如果發送到只有一個號碼,你可以使用此功能,假設不同的值ATA不同時間如何將固定值t替換爲請求中的變量名稱。 addparameter聲明

request.AddParameter("application/json", "{""messages"":[{""from"":""sender"",""to"":[""238045366373""],""text"":""May the God be with you Jolaoluwa!""}]}", ParameterType.RequestBody) 
+0

我得到的錯誤消息是「編譯器錯誤消息:BC30516:重載解析失敗,因爲沒有可訪問的'AddParameter'接受這個參數數目。請幫忙 - – Pope

+0

請通過導致問題的代碼...嘗試在變量字符串。 – scartag

+0

request.AddParameter(「application/json」,「{」「messages」「:[{」「from」「:」&sender&「,」「to」「:[」&foneno&「],」「text」「: 「願上帝與你同在Jolaoluwa!」「}}}」,ParameterType.RequestBody) – Pope

回答

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 

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) 
+0

我已經能夠成功地發送消息到單個和固定號碼,但問題出現時,我發送到多個號碼和可變數字,所以我需要代表數字,發件人和消息作爲變量 – Pope

+0

是的,我儘可能多但我很驚訝,當我將固定數字更改爲變量名稱並且代碼中出現錯誤 – Pope

+0

是的,謝謝。我得到了「遠程服務器返回錯誤:(404)Not Found。 說明:執行當前Web請求期間發生未處理的異常請查看堆棧跟蹤以獲取有關錯誤的更多信息以及源自代碼 異常詳細信息:System.Net.WebException:遠程服務器返回錯誤:(404)未找到 源錯誤: 58行:Dim baseURL時作爲字符串=「HTTPS://api2.bulksms .com/apisms/1/text/single「 Line 59: Line 60:Dim s As String = client.DownloadString(baseurl) Line 61: Line 62: – Pope