Sending a url to external server

JHatman

Banned
Joined
Oct 28, 2008
Messages
2,008
Hi guys. Ok i'll make this short n sweet. I've set up an account with a company call bulksmsportal. Basically i send their server a url with some login details, a message and a phone number. Their server is supposed to fire off an sms based on the details I've entered.

I'm also wanting to do this in asp but haven't a clue how pls hulp!! This is the url:

SendURL = "http://www.bulksmsportal.co.za/httppost4.aspx?type=singlesms&username=xxxx&password=xxxx&" & "Number=" & telNum & "&Message=" & txtMessage

How do I fire it off from within code? All the examples I've googled have been in XML but according to them it can be a straightforward url as well.
 
Last edited:

JHatman

Banned
Joined
Oct 28, 2008
Messages
2,008
What programming language are you using?

ASP atm. I've considered converting it to asp.net as well, depends on what examples anyone posts and and I'll try it out. Even in asp.net myself and a colleague have been scratching our heads for a while on this!
 

bullfrog

Expert Member
Joined
Apr 23, 2006
Messages
2,068
This is their api site: http://www.mymobileapi.com/http.aspx

I am not too clued up on asp, but use php. This is the example of how to do it with php:

PHP:
$data= array(
"Type"=> "sendparam", 
"Username" => "username",
"Password" => "password",
"live" => "true",
"numto" => "0123456789",
"data1" => "My test message"
) ; //This contains data that you will send to the server.
$data = http_build_query($data); //builds the post string ready for posting
echo do_post_request('http://www.mymobileapi.com/api5/http5.aspx', $data);  //Sends the post, and returns the result from the server.
?>

<?php 
//Posts data to server and recieves response from server
//DO NOT EDIT unless you are sure of your changes
  function do_post_request($url, $data, $optional_headers = null)
  {
     $params = array('http' => array(
                  'method' => 'POST',
                  'content' => $data
               ));
     if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
     }
     $ctx = stream_context_create($params);
     $fp = @fopen($url, 'rb', false, $ctx);
     if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
     }
     $response = @stream_get_contents($fp);
     if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
     }
     $response;
     
     
  }
?>

I've removed all the response stuff to make it a bit shorter. You can download the full example from the site above. So it's just a matter of figuring out what the equivalent commands in asp is and changing syntax.
 

crazy_cat

Well-Known Member
Joined
Aug 21, 2007
Messages
326
i think the call needs to be a POST request.

What you could do is add the webservice as a web reference in VS and auto generate a WSDL (proxy) class file for you, you then will be able to call the service from code.

look here http://www.mymobileapi.com/web-services.aspx
 
Last edited:

JHatman

Banned
Joined
Oct 28, 2008
Messages
2,008
This is their api site: http://www.mymobileapi.com/http.aspx

I am not too clued up on asp, but use php. This is the example of how to do it with php:

PHP:
$data= array(
"Type"=> "sendparam", 
"Username" => "username",
"Password" => "password",
"live" => "true",
"numto" => "0123456789",
"data1" => "My test message"
) ; //This contains data that you will send to the server.
$data = http_build_query($data); //builds the post string ready for posting
echo do_post_request('http://www.mymobileapi.com/api5/http5.aspx', $data);  //Sends the post, and returns the result from the server.
?>

<?php 
//Posts data to server and recieves response from server
//DO NOT EDIT unless you are sure of your changes
  function do_post_request($url, $data, $optional_headers = null)
  {
     $params = array('http' => array(
                  'method' => 'POST',
                  'content' => $data
               ));
     if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
     }
     $ctx = stream_context_create($params);
     $fp = @fopen($url, 'rb', false, $ctx);
     if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
     }
     $response = @stream_get_contents($fp);
     if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
     }
     $response;
     
     
  }
?>

I've removed all the response stuff to make it a bit shorter. You can download the full example from the site above. So it's just a matter of figuring out what the equivalent commands in asp is and changing syntax.

Thanks Bullfrog, my PHP is not too great but will play with it a little.

i think the call needs to be a POST request.

What you could do is add the webservice as a web reference in VS and auto generate a WSDL (proxy) class file for you, you then will be able to call the service from code.

look here http://www.mymobileapi.com/web-services.aspx

I find mymobileapi earlier but missed this page I think. Gonna dig around a little in there. I'll do a full example here later if I get it working this afternoon.
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Check my blog on how to call web services using Classic ASP

As far as sending the URL to the company, that "sendURL" should be in the POST of a form unless you use the web service (which I'll recommend obviously)
 

James

Expert Member
Joined
May 26, 2004
Messages
2,617
If you do use PHP, if you are not happy with streams you can use CURL. I have a new sites which use a 3rd Party sms service and I quite happily use CURL to POST the data. There are many guides and it is fairly simple to do.

I have snippets if you need.
 

JHatman

Banned
Joined
Oct 28, 2008
Messages
2,008
ok This is what I've got so far. The XML data is a tester for now and I'm be putting live data in there but thats basically the format I've been given to use. I suspect there is something wrong with my URL though.

This is the URL suggested to me from SMSPortal

PHP:
http://www.mymobileapi.com/api5/http5.aspx?Type=send&username=xxx&password=yyy&xmldata=yourxmldatastring

And Here is the XML Data to be send. The blue indicates its not mandatory.

<senddata>
<settings>
<live>True</live>
return_credits>True</return_credits>
<return_msgs_success_count>True</return_msgs_success_count>
<return_msgs_failed_count>True</return_msgs_failed_count>
<return_entries_success_status>True</return_entries_success_status>
<return_entries_failed_status>True</return_entries_failed_status>
<default_senderid />

<default_date>04/Mar/2009</default_date>
<default_time>11:15</default_time>
<default_curdate>04/Mar/2009</default_curdate>
<default_curtime>11:15</default_curtime>
<default_data1>This is a default msg</default_data1>
<default_data2 />
<default_flash>False</default_flash>
<default_type>SMS</default_type>
<default_costcentre>NA</default_costcentre>

</settings>

<entries>
<numto>0832297941</numto>
<customerid>UnqiueValue1</customerid>
<Senderid>Senderid</Senderid>
<data1>This is a test message</data1>
<data2 />
<flash>False</flash>
<type>SMS</type>
<costcentre>NA</costcentre>
<default_validityperiod>0</ default_validityperiod >

</entries>
</senddata>

So far this is the code I've put together just to test it and try get it going. Take a look at the way I've formed my URL, this is my biggest suspect atm as to why this isn't working, perhaps where I'm trying to send the xml data as a parameter. Something doesn't seem right there.

PHP:
Public Function SendSMS()
    dim yourxmldatastring

    yourxmldatastring="<senddata>" & _
    "<settings>" & _
    "<live>True</live>" & _
    "<default_date>04/Mar/2009</default_date>" & _
    "<default_time>11:15</default_time>" & _
    "</settings>" & _

    "<entries>" & _
    "<numto>1234567890</numto>" & _
    "<customerid>UnqiueValue1</customerid>" & _
    "<time>11:15</time>" & _
    "<data1>This is a test message </data1>" & _
    "</entries>" & _
    "</senddata>"

    Dim xmlhttp

    ' Create an xmlhttp object:

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.open "POST" ,"http://www.mymobileapi.com/api5/http5.aspx?Type=send&username=User_Name&password=Pass_word&xmldata=",False
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.send yourxmldatastring
    Set xmlhttp = Nothing 

End Function
 
Last edited:

JHatman

Banned
Joined
Oct 28, 2008
Messages
2,008
Send XML String/Data via HTTP Post

IT WORKS. The final working product :D

PHP:
Public Function SendSMS(txtMessage, telNum)
    Dim xml_data 
    Dim SendURL
    Dim oXMLHttp
    
    SendURL = "http://www.mymobileapi.com/api5/http5.aspx?Type=send&username=user_name&password=pwd12&xmldata="

    xlm_data = "<senddata>" & _
    "<settings>" & _
    "<live>True</live>" & _
    "<default_date>04/Mar/2009</default_date>" & _
    "<default_time>11:15</default_time>" & _
    "</settings>" & _
    "<entries>" & _
    "<numto>" & telNum & "</numto>" & _
    "<customerid>UnqiueValue1</customerid>" & _
    "<data1>" & txtMessage & "</data1>" & _
    "</entries>" & _
    "</senddata>"

    SendURL = SendURL + xlm_data
    
    Set oXMLHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
    
    'Opens the connection to the WinSMS Gateway.
    oXMLHttp.Open "GET", SendURL, False
    'Send the Data
    oXMLHttp.send()

End Function
 
Last edited:

The Axe Dude

Senior Member
Joined
Feb 14, 2008
Messages
585
As far as I can see, the issue is you were using a POST query, whereas the URL makes use of GET. :p
 

JHatman

Banned
Joined
Oct 28, 2008
Messages
2,008
As far as I can see, the issue is you were using a POST query, whereas the URL makes use of GET. :p

I'm still not sure what the difference is but gonna play with this a little more and see what other options available :D
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
I'm still not sure what the difference is but gonna play with this a little more and see what other options available :D

The difference is simple:

a GET sends data via the url (which is available for anyone who wants to snoop to see) and looks like this: www.youdomain.com/page.asp?this=anobjectintheget
a POST doesn't send the data through the url at all

Your code would change slightly to allow for the post to happen seeing as you try to use a POST but still do URL query (like GET)

Here's your code modified a bit:

Code:
Public Function SendSMS(txtMessage, telNum) 
    Dim xml_data  
    Dim SendURL 
    Dim oXMLHttp 
     
   [color=red]xlm_data = "Type=send&username=user_name&password=pwd12&xmldata="[/color] 

    xlm_data = xml_data & "<senddata>" & _ 
    "<settings>" & _ 
    "<live>True</live>" & _ 
    "<default_date>04/Mar/2009</default_date>" & _ 
    "<default_time>11:15</default_time>" & _ 
    "</settings>" & _ 
    "<entries>" & _ 
    "<numto>" & telNum & "</numto>" & _ 
    "<customerid>UnqiueValue1</customerid>" & _ 
    "<data1>" & txtMessage & "</data1>" & _ 
    "</entries>" & _ 
    "</senddata>" 

    SendURL = SendURL + xlm_data 
     
    Set oXMLHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0") 
     
    oXMLHttp.Open "POST", [color=red]"http://www.mymobileapi.com/api5/http5.aspx"[/color], False 
    'Send the Data 
    oXMLHttp.send([color=red]xlm_data[/color]) 

End Function

Here's a direct link to how to call a web service using classic ASP
 
Last edited:

JHatman

Banned
Joined
Oct 28, 2008
Messages
2,008
Thanks Acid, works great. I got some spare time in the office now so try that function on your blog, seems nice n tidy. Thanks!!
 
Top