-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Netduino send Twilio SMS #2
Labels
Comments
See http://forums.netduino.com/index.php?/topic/6799-https-support-on-n2/ The Netduino's .NET does not support SSL. |
My attempted Twilio code: using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.Text;
namespace AuthNet
{
public class Program
{
public static void Main()
{
// write your code here
var Interface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];
Interface.EnableDynamicDns();
Interface.EnableDhcp();
Debug.Print("IPAddress: " + Interface.IPAddress);
foreach (var d in Interface.DnsAddresses)
Debug.Print("DNS: " + d);
Debug.Print("Started");
string _Host = "api.twilio.com";
var Entry = Dns.GetHostEntry(_Host);
var _Address = new IPAddress(Entry.AddressList[0].GetAddressBytes());
var _Port = 443;
var accountSid = "";
var authToken = "";
var s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPHostEntry ipHostInfo = Dns.GetHostEntry(_Host);
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint endPoint = new IPEndPoint(ipAddress, _Port);
//var EndPoint = new IPEndPoint(_Address, 80);
s.Connect(endPoint);
var url = "http://api.twilio.com/2010-04-01/Accounts/" + accountSid + "/SMS/Messages.json";
//var text = KeyPadIndexToChar[(int)KeyCode].ToString();
//string text = "\"" + _ID.Substring(0, 2) + " " + _Result + "\""; // +Result;
string body = "From=+12356&To=+12323432&Body=testing";
var databuilder = new StringBuilder();
databuilder.AppendLine("POST " + url + " HTTP/1.1");
databuilder.AppendLine("Accept: application/json");
databuilder.AppendLine("Content-Type: application/x-www-form-urlencoded; charset=utf-8");
//databuilder.AppendLine("Content-Type: text/plain; charset=utf-8");
databuilder.AppendLine("Host: " + _Host);
databuilder.AppendLine("Content-Length: " + body.Length);
string credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(accountSid + ":" + authToken));
databuilder.AppendLine("Authorization: Basic " + credentials);
databuilder.AppendLine("Connection: Keep-Alive");
databuilder.AppendLine("");
databuilder.AppendLine(body);
var databytes = Encoding.UTF8.GetBytes(databuilder.ToString());
System.Net.Security
Debug.Print("Sending...");
var numbytessend = s.Send(databytes);
Debug.Print("Sent");
var buff = new byte[10000];
var numbytesread = s.Receive(buff, 0, 10000, SocketFlags.None);
if (numbytesread > 0)
{
var chars = Encoding.UTF8.GetChars(buff, 0, numbytesread);
Debug.Print("Result: " + new String(chars));
}
var LED = new OutputPort(Pins.ONBOARD_LED, false);
while (true)
{
LED.Write(true);
Thread.Sleep(200);
LED.Write(false);
Thread.Sleep(100);
}
}
}
} |
Glavin001
added a commit
that referenced
this issue
May 14, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/23394895/send-message-using-a-webrequest-and-twilio
The text was updated successfully, but these errors were encountered: