HTTP POST sms without user interaction

HTTP POST sms without user interaction SearchSearch
Author Message
Suvinay
New member
Username: Suvinay

Post Number: 1
Registered: 07-2004
Posted on Sunday, July 25, 2004 - 03:21 pm:   

Hi Bryce,
I am testing the trial version of NowSMS 5.5.
I am working on a group messaging service. I have an SMPP connection to an SMSC to submit messages.
Group messaging works by users logging on to a website, creating groups and adding contact phone numbers to the groups.
To send messages the user simply chooses a group...enters information in a text box and submits send. The asp page retrieves all the contacts in the group and submits the same to NowSMS via httppost.

Building the contacts, groups, authorising users etc I can easily do via asp pages. Problem arises when I need to post the url to NowSMS (the gateway is running on another ip, computer)

The main problem is that I don't want the user to be able to view what url is being sent or what information is being sent where. Instead of creating separate SMS User accounts for each user, I am creating only a single user account for all users with a username/password. When a user sends message to a group, I want to use the url submission feature of NowSMS and automatically submit the common username/password.

http://username:password@xxx.xxx.xxx.xxx:8800/?PhoneNumber=%2Bxxxxxxxx,%2Bxxxxxxx,%2Bxxxxxxxxxxx&Text=abc+def+ghi
(all the phone numbers in the same url seperated by commas).

If I use http get method the user can see this url which I don't want.

If I submit through http post method a window pops up asking user to enter username and password.

I don't want any interaction with the user and neither should he be able to see what is being sent or where it is being sent. Furthermore I want to use some kind of form so that the user cannot simply save the page and view the contents and see the url being sent. Please help? Any examples you can point me to?
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 3144
Registered: 10-2002
Posted on Wednesday, July 28, 2004 - 08:38 pm:   

Hi Suvinay,

This is a good question. Unfortunately, I am not very familiar with ASP, so I have had to spend some time learning ASP.

Before I start with an ASP example ... let me start by referring to a PHP example that we have out here in the discussion forum:

http://support.nowsms.com/discus/messages/1/3692.html

Basically, we include a function called "SendSMS" in the PHP script. So when the PHP script wants to send a message, rather than redirecting to the NowSMS server, it generates a brand new HTTP request to go to the NowSMS server.

So the user never directly connects to the NowSMS server. The PHP script running on the web server makes the connection to the NowSMS server when it wants to send a message.

The example in the thread referenced above is a great starting point for doing this from PHP.

You can do something very similar with ASP. So, I set out to put together an example of how to do this in ASP.

In the end, I put together the following simple example using ASP.Net. I think you can do similar things with ASP, but I decided to use ASP.Net ... so hopefully you'll still be able to put this example to use.

Here's my ASP script. Basically, when this script is run, it tries to connect to NowSMS at the specified server address and port, and it sends a message to a predefined list of recipients.

The end-user connects to your web server ... but the end-user never connects directly to the NowSMS server. Instead, the script running on the web server performs that connection.

Save the following as "SendSMS.aspx" for starters ...

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>

<SCRIPT Language="VB" Option="Explicit" runat="server">

Function SendSMS(strHost As String, strPort As String, strUserName As String, strPassword As String, strRecip as String, strMsgText as String) As String

Dim objURI As URI = New URI("http://" & strHost & ":" & strPort _
& "/?User=" & HttpUtility.URLEncode(strUserName) _
& "&Password=" & HttpUtility.URLEncode(strPassword) _
& "&PhoneNumber=" & HttpUtility.URLEncode(strRecip) _
& "&Text=" & HttpUtility.URLEncode(strMsgText))
Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
Dim objStream As Stream = objWebResponse.GetResponseStream()
Dim objStreamReader As StreamReader = New StreamReader(objStream)
Dim strHTML As String = objStreamReader.ReadToEnd

SendSMS = strHTML

End Function

</SCRIPT>

<%= SendSMS("127.0.0.1", 8800, "username", "password", "+99999999", "Test Message") %>

In this example, the NowSMS server, user account, recipient and message are all pre-defined. But basically, you just need to have your script execute the SendSMS function with the parameters that you want to pass to it.

This script returns back the output that came from the submission to the NowSMS server ... but you don't have to do that.

This script could also use some error handling. But I think it is enough to get you started in the right direction.

-bn