1

I need to change the sender and 238045366373 to variable strings such that that can assume different values ata different times

request.AddParameter("application/json", "{""messages"":[{""from"":""sender"",""to"":[""238045366373""],""text"":""May the God be with you Jolaoluwa!""}]}", ParameterType.RequestBody)
msmolcic
  • 6,407
  • 8
  • 32
  • 56
Pope
  • 55
  • 2
  • 8
  • The error message i get is " Compiler Error Message: BC30516: Overload resolution failed because no accessible 'AddParameter' accepts this number of arguments." Please help – – Pope Jan 13 '16 at 11:25
  • please past the code that is causing the issue ... the attempt at the variable strings. – scartag Jan 13 '16 at 11:30
  • request.AddParameter("application/json", "{""messages"":[{""from"":"&sender&",""to"":["&foneno&"],""text"":""May the God be with you Jolaoluwa!""}]}", ParameterType.RequestBody) – Pope Jan 13 '16 at 11:36
  • I've added an answer. – scartag Jan 13 '16 at 11:43

1 Answers1

0

If you are sending to only a single number you could use this function.

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

All you'll need to do is call SendInfoBip as shown below.

    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

If you require the correct way of using variables instead of the hardcoded values as you requested early see below.

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)
scartag
  • 17,548
  • 3
  • 48
  • 52
  • I ave been able to successfully send messages to single and fixed numbers, but the issue arose when i am sending to multiple numbers and variable numbers, so i need to represent the numbers, sender and message as variable – Pope Jan 13 '16 at 11:56
  • yes, i tot as much but i was surprised when i changed the fixed number to a variable name and the code came up with an error – Pope Jan 13 '16 at 12:03
  • yes, Thank you. I got "The remote server returned an error: (404) Not Found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The remote server returned an error: (404) Not Found. Source Error: Line 58: Dim baseurl As String = "https://api2.bulksms.com/apisms/1/text/single" Line 59: Line 60: Dim s As String = client.DownloadString(baseurl) Line 61: Line 62: – Pope Jan 13 '16 at 12:39
  • no, that is not what i am using on the code, i just typed it i the question – Pope Jan 13 '16 at 13:23
  • But why cant we just use the below script as provided by infobip on their website and substitute fixed valued with variables string as in the below statement request.AddParameter("application/json", "{""from"":""infoSMS"", ""to"":[""2348055558307"",""2348022265313""],""text"":""Test SMS.""}", ParameterType.RequestBody) – Pope Jan 13 '16 at 13:34
  • i got this response BadRequest{"requestError":{"serviceException":{"messageId":"BAD_REQUEST","text":"Bad request"}}} – Pope Jan 13 '16 at 13:48
  • @Pope i think i made the mistake of using the one you pasted here in the comments .. instead of the one originally in the question .. will make the changes now. – scartag Jan 13 '16 at 13:53
  • copied and pasted, will keep trying – Pope Jan 13 '16 at 13:57
  • @Pope Glad to help :) – scartag Jan 13 '16 at 14:06
  • please if i decided to use the 1st code you sent using Dim baseurl As String = "http://api2.infobip.com/api/sendsms/plain", how will i capture the response as a string and display it of the screen – Pope Jan 13 '16 at 14:21
  • @Pope You can change the return type of the method to return string instead of boolean and remove the boolean test at the end of the method and return the value "s" instead. i can modify it to reflect that if you want. – scartag Jan 13 '16 at 14:24
  • please do, to be very sure. Thank you – Pope Jan 13 '16 at 15:18
  • https://stackoverflow.com/questions/34865052/why-do-i-get-error-message-when-i-loop – Pope Jan 18 '16 at 22:24