cloudflying
8/26/2012 - 3:56 PM

Make a Phone call with Twilio

Make a Phone call with Twilio

Imports System.Net
Imports System.Text
Imports System.IO


Public Function makeaCall() as string
    Dim AccountSID As String = "aaaaaaa"
    Dim authToken As String = "123"
    Dim uri As String = "https://api.twilio.com/2010-04-01/Accounts/" & AccountSID & "/Calls"
    Dim data As String = "From=+15551234567&To=+15557654321&Url=http://twimlets.com/message?Message[0]=You%20have%20successfully%20called%20me!&Method=POST"
    Dim authInfo As String = AccountSID & ":" & authToken
    authInfo = Convert.ToBase64String(Encoding.[Default].GetBytes(authInfo))

    Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
    request.Method = WebRequestMethods.Http.Post
    request.ContentLength = data.Length
    request.Headers("Authorization") = "Basic " & authInfo
    request.ContentType = "application/x-www-form-urlencoded"
    Dim writer As New StreamWriter(request.GetRequestStream)
    writer.Write(data)
    writer.Close()
    Dim oResponse As HttpWebResponse = request.GetResponse()
    Dim reader As New StreamReader(oResponse.GetResponseStream())
    Dim tmp As String = reader.ReadToEnd()
    oResponse.Close()
    return tmp
End Function