I am working on integrating a third party SMS application. The requirement is to send SMS to ten mobile numbers on single click of button on a web page at my site.
We have been provided with a URL in which we have to add a phone number and message to be sent. The URL accepts only ONE phone number at a time.
I have a list of phone numbers to which I have to send the same message one by one .
On looping through the list , I add a phone number to url and do Response.Redirect(url) in each iteration.
But this only ends up sending SMS to the first phone number in list as first time Response.Redirect() occurs , it takes browser to external site specified by the given Url and rest of for loop is not executed i.e rest of phone numbers are not embedded in url.
string[] phNos = { "91999999998", "91999999996" ,"91999999995"}; // Sample Mobile nos.
for(int i=0;i<phNos.Length;i++)
{
url = "baseurl/PushURL.fcgi?0&mobileno=" + phNos[i] + "&message="+ masg;
Response.Redirect(url);
}
I read about Server.Transfer() but this is can’t be used for sending to external site.
Is my requirement feasible ? Please help how can I implement it .
Response.Redirect redirects the users browser to the given URL, as you found out.
What you want to do is to have your server access the URL(s) needed, using server-to-server communication. You can use WebClient to easily do this.
Note that this will retrieve the urls, effectively calling the API, sequentially and synchronously, which might not be what you want. If you want to do it in parallel, you can use
DownloadStringAsyncon WebClient, but you will need to code a mechanism that lets you wait until all the requests finished. This depends on what you want, how many numbers there might be, and your performance constraints.