1

Here is my C# code

var UriBuilder = new UriBuilder("http://smsgateway.me/api/v3/messages/send/");
var parameters = HttpUtility.ParseQueryString(string.Empty);
parameters["email"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:email", NamespaceManager).Value;
parameters["password"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:password", NamespaceManager).Value;
parameters["device"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:device", NamespaceManager).Value; ;
parameters["number"] = "123456789";//any number
parameters["message"] = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SMS_TO_BE_SENT", NamespaceManager).Value; ;
UriBuilder.Query = parameters.ToString();
//UriBuilder.Fragment = "some_fragment";

Uri finalUrl = UriBuilder.Uri;
var request = WebRequest.Create(finalUrl);

// Get the response.
WebResponse result = request.GetResponse();

And here is sample PHP code

<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('[email protected]', 'password');

$deviceID = 1;
$numbers = ['+44771232343', '+44771232344'];
$message = 'Hello World!';

$options = [
'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes
'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent
];

//Please note options is no required and can be left out
$result = $smsGateway->sendMessageToManyNumbers($number, $message, $deviceID, $options);
?>

The number in the PHP example is an array. How can I pass an array in the query string using HttpUtility.ParseQueryString?

2
  • It's unclear what you are asking. Do you want to implement the PHP example using C#? Commented Oct 10, 2015 at 11:38
  • @ venerik Yes. All other things are working fine except Number in Commented Oct 10, 2015 at 12:06

1 Answer 1

2

You can add an array of numbers to the query string like this:

parameters["number[0]"] = "123456789";
parameters["number[1]"] = "987654321";

I tested it with this link

http://smsgateway.me/api/v3/messages/send?email=xxx&password=xxx&device=xxx&number[0]=123456789&number[1]=987654321&message=test

and that works.

EDIT As per your comment.

I'm not familiar with InfoPath but based on this documentation you can add multiple numbers to the query like this:

XPathNavigator root = MainDataSource.CreateNavigator();
XPathNodeIterator nodes = root.Select("/my:myFields/my:group1/my:myGroup/my:myNumber", NamespaceManager);
var i = 0;
while (nodes.MoveNext())
{
    parameters["number[" + i + "]"] = nodes.Current.Value;
    i++;
}

Be careful though, you might run in to problems when the URI becomes extremely long.

Sign up to request clarification or add additional context in comments.

6 Comments

thanks. it is working. venerik is it possible to make these numbers varible? means if once I have 100 numbers to send sms and again i have 80 numbers to send sms
Not quite clear what you mean but every request is independent of other requests. So, sending the first 100 messages you can use number[0] through number[99] and sending the next 80 message you can use number[0] through number[79]. By the way: accepting the answer if much appreciated B-)
My Mistake that I am not able to clarify my self. Basically I am trying to create an infopath form. when clicked on button on form SMSs will be sent. Quantity of Mobile Numbers is not defined. It is not possible for me to tell whether there will be 100 Mobile Numbers or 80 Mobile Numbers or 1000 Mobile Numbers. So in filling form a person enters 100 Mobile Numbers, HOW IN THE CODE I CAN DEFINE THIS? Mobile Numbers will be manually entered in form.
I have Created a field myNumbers and entered mobile numbers, separated my commas. But SMSGATEWAY.ME is treating all numbers as one. What I am Doing wrong here?
As I said, I'm not familiar with InfoPath but I think you should configure a repeating table (myGroup) containing a field for a number (myNumber). The repeating table gives the user the opportunity to enter multiple numbers. In that case you can use my code to insert the numbers in the query string.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.