Now SMS API

Now SMS API SearchSearch
Author Message
Saeed Paksima
Posted on Wednesday, April 23, 2003 - 11:31 am:   

Hi,
I am trying to incorporate SMS text message sending capability into my web site using ASP.Net.
My question is :
1- Are there any APIs for Now SMS so that I can develope my server side app?
2- By now I can easily send my requst to the gateway but the problem is the authentication on the gateay, and how to get the result code of the gateway to display on the client web page

Generally what's the best way to create a web page from which users can send SMS messages?
Bryce Norwood - NowSMS Support (Bryce)
Posted on Friday, April 25, 2003 - 08:51 pm:   

Hi Saaed,

The interface into NowSMS is HTTP based. So that makes it pretty flexible to interface with.

I've had one ASP developer tell me that they were using a freeware product called AspTear to do the interfacing. You can find AspTear at the following link:

http://www.alphasierrapapa.com/IisDev/Components/AspTear/

There are also a variety of ways to do it with Microsoft tools ... for example, the following links might be helpful:

http://www.asp101.com/samples/http.asp
http://www.asp101.com/samples/winhttp5.asp

The second of these two links seems a little easier to deal with. View the ASP code associated with each. You may need to download some software from the Microsoft site to add the objects associated with either appoach. If you're trying the "winhttp5" script approach, when it links you to the Microsoft web site to download "Microsoft Windows HTTP Services 5.0 Software Development Kit", the link doesn't take you directly there. You need to search on "HTTP Services" to find it.

Another link at the Microsoft MSDN is also helpful:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmobjxmlhttprequest.asp

The only problem with all of this, is how do you set an "Authorization:" header? I'm not an expert with ASP or any of the above approaches, but I don't see any built-in support for Authorization.

While you could disable the authentication on the NowSMS server, and just use IP address restrictions to limit who can connect to the server to submit messages ... it's relatively easy to build your own "Authorization:" header in the HTTP request.

With the XMLHTTP object, you can use the setRequestHeader method against the object to set a header. The problem is that the username and password are Base64 encoded in the authorization header, which makes it a little difficult to construct.

If you want to cheat in constructing the HTTP Authorization header (don't want to learn how to do Base64 encoding), the easiest way to cheat is to use a web browser to connect to a site that requires the same username and password, and trap the result. You can do this with NowSMS itself by doing the following:

1.) On the MMSC page of the NowSMS configuration dialog, set the "Admin User" and "Admin Password" fields to the username and password that you plan to use for your "SMS User" account on NowSMS.

2.) Put the MMSC into debug mode by manually editing MMSC.INI and adding Debug=Yes under the [MMSC] section.

3.) (Re)start the MMSC service. You can do this through the "MMSC" page of the configuration dialog. Check/uncheck (as appropriate) "Activate MMSC Service" and click "Apply".

4.) From a web browser on the same machine, connect to http://127.0.0.1:9999/admin (where 9999 is the "HTTP Port Number" configured on the "MMSC" page of the configuration dialog). You'll be prompted for a username and password, so enter the username/password that you configured.

5.) Go into the NowSMS program directory and open MMSCDEBUG.LOG with Notepad or Wordpad or the text viewer of your choice. The reason I had you login to the MMSC is because when the MMSC receives an HTTP request in debug mode, it does a hex dump of the request to the MMSCDEBUG.LOG file. In the dump of that request, you should see the "Authorization:" header that IE used to login to the MMSC. The header will look something like this: "Authorization: Basic Ym9zY2g6Ym9zY2g=".

6.) You can now use setRequestHeader something like this:

xmlhttp.setRequestHeader("Authorization", "Basic Ym9zY2g6Ym9zY2g=")

Now after I've said all that ... I see you're actually using ASP.Net. One of the links above has links to an ASP.Net version of its example script, but it's kind of weak.

I was curious to find out how to add custom headers using the WebRequest (or HTTPWebRequest) classes in .NET ... and I found the following link helpful:

http://msdn.microsoft.com/msdnmag/issues/01/09/cweb/default.aspx

Figure 7 in the above article shows an example of setting custom headers in a .NET style HTTPWebRequest. Some headers are set on the HTTPWebRequest directly, while others like "Authorization" are set through ".Headers.Add" against the object.

And ... now armed with a bit more information to refine my search of the web ... I find the following link:

http://www.dotnet247.com/247reference/msgs/16/84325.aspx

That link actually shows an example using .NET's "HTTPWebRequest" class ... and using an "Authorization" header. It even calls another function that converts the username/password string to Base64 (encode the username and password as username:password before encoding it in Base64).

Good luck!

And if you have any helpful pointers to share after going through this process, please take the time to reply back here ... as I'm sure others would find this useful.

-bn
Saeed
Posted on Sunday, April 27, 2003 - 07:15 am:   

Hi Bryce,

Thank you very much for the tips.I'm just working on them and will surely share the outcome.

Regards,

Saeed
Bryce Norwood - NowSMS Support (Bryce)
Posted on Tuesday, April 29, 2003 - 07:34 pm:   

Saeed,

A thought just crossed my mind ...

I spent a lot of time and energy in my previous response talking about building the Base64 "Authorization" header to login to NowSMS when you submit a request.

On further thought I realised that it was not necessary to use an "Authorization" header to submit messages to NowSMS. Granted, an "Authorization" header is how a web browser submits username and password information to a web server ... so it is the normal way to login to a web server.

However, NowSMS also supports the ability for applications to include the username and password in the HTTP GET request. Use the "User" and "Password" variables to include the username and password when submitting a message ... as a simple alternative to this "Authorization" header.

For example:

http://127.0.0.1:8800/?user=username&password=password&phonenumber=%2b44777777777&text=test+message

I hope that helps ...

-bn