Username: Password:

Forgot password? Sign up


Sign up

Receive 5 free credits.
Easy to try, simple to use.


register

Test Network

+


VB.NET code sample

Simplest case - sending a single message:

' We use the HttpUtility class from the System.Web namespace
Imports System.Web
Imports System.IO  
Imports System.Net  
Imports System.Text 


Public Class Application
	Public Shared Sub Main()
		
		Dim request As HttpWebRequest
		Dim response As HttpWebResponse = Nothing
		Dim reader As StreamReader
		Dim address As Uri   

		Dim username As String
		Dim password As String
		Dim message As String
		Dim msisdn As String
		  
		Dim data As New StringBuilder  
		Dim byteData() As Byte  
		Dim postStream As Stream = Nothing  

		' If your firewall blocks access to port 5567, you can fall back to port 80:
		' address = New Uri("http://usa.bulksms.com/eapi/submission/send_sms/2/2.0?")
		' (See FAQ for more details.)
		address = New Uri("http://usa.bulksms.com:5567/eapi/submission/send_sms/2/2.0")

		' Create the web request  
		request = DirectCast(WebRequest.Create(address), HttpWebRequest)  

		' Set type to POST  
		request.Method = "POST"  
		request.ContentType = "application/x-www-form-urlencoded"  

		' Create the data we want to send
		username = "myusername"
		password = "xxxxxx"
		message = "Testing Vb special characters: @#$è"
		msisdn = "44123123123"
		
		data.Append("username=" + HttpUtility.UrlEncode(username, System.Text.Encoding.GetEncoding("ISO-8859-1")))
		data.Append("&password=" + HttpUtility.UrlEncode(password, System.Text.Encoding.GetEncoding("ISO-8859-1")))
		data.Append("&message=" + HttpUtility.UrlEncode(message, System.Text.Encoding.GetEncoding("ISO-8859-1")))
		data.Append("&msisdn=" + HttpUtility.UrlEncode(msisdn, System.Text.Encoding.GetEncoding("ISO-8859-1")))
		
		' Create a byte array of the data we want to send
		byteData = System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(data.ToString())
		'byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())  

		' Set the content length in the request headers  
		request.ContentLength = byteData.Length  

		' Write data  
		Try  
			postStream = request.GetRequestStream()  
			postStream.Write(byteData, 0, byteData.Length)
		Catch ex As Exception
			Console.WriteLine(ex.to String())
		Finally
			If Not postStream Is Nothing Then postStream.Close()
		End Try

		Try
			' Get response
			response = DirectCast(request.GetResponse(), HttpWebResponse)

			' Get the response stream into a reader
			reader = New StreamReader(response.GetResponseStream())

			' Console application output
			' Console.WriteLine(reader.ReadToEnd())

			Dim result As String = reader.ReadToEnd()
			Dim tokens() As String
			tokens = result.Split("|")

			If tokens.Length() <> 3 Then
				Console.WriteLine("Error: could not parse valid return data from server")
			Else
				If String.Compare(tokens(0).ToString, "0") = 0 Then
					Console.WriteLine("Message sent: batch " & tokens(2).ToString())
				Else
					Console.WriteLine("Error sending message: " & tokens(0) &" "& tokens(1))
				End If
			End if
		Catch ex As Exception
			Console.WriteLine(ex.to String())
		Finally
			If Not response Is Nothing Then response.Close()
		End Try

	End Sub
End Class