Start a new topic
Answered

Push server

Could someone tell me what do I need to "make" a push server?


or to push data with my (domain hosted) server?


I mean that my server automaticaly execute (some) code in order to send push data...


Which technology do I need?


thank you everybody


Best Answer

you have to generate a http Post request to the lametric servers.

I am a .net developer her is some sample code in C#


lblErr.Text = ""; string authInfo = "Auth token from la Metric"; string url = "https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.xxxxxxxxFrom La Metricxxxxxxxxxxxxxx";

string data = string.Format("{{\"frames\": [{{ \"index\": 0, \"text\": \"{0}\", \"icon\": \"i555\" }}, {{ \"index\": 1, \"text\": \"{1}\", \"icon\": \"a230\" }}, {{ \"index\": 2, \"text\": \"{2}\", \"icon\": \"a112\" }} ] }}", txtMessage.Text,txtMessage.Text,txtMessage.Text);

try {

var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.153212d2df2b9492a5502dd876eac046/2");

httpWebRequest.Accept = "application/json"; httpWebRequest.Headers.Add("X-Access-Token", authInfo); httpWebRequest.Headers.Add("Cache-Control", "no-cache"); httpWebRequest.Host = "developer.lametric.com";

httpWebRequest.ContentType = "text/json";

httpWebRequest.ContentLength = data.Length;

httpWebRequest.Method = "POST";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))

{

streamWriter.Write(string.Format("{0}", data));

streamWriter.Flush();

streamWriter.Close();

}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))

{

var result = streamReader.ReadToEnd();

}

}

catch (Exception ex)

{

lblErr.Text = ex.Message;

}

1 Comment

Answer

you have to generate a http Post request to the lametric servers.

I am a .net developer her is some sample code in C#


lblErr.Text = ""; string authInfo = "Auth token from la Metric"; string url = "https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.xxxxxxxxFrom La Metricxxxxxxxxxxxxxx";

string data = string.Format("{{\"frames\": [{{ \"index\": 0, \"text\": \"{0}\", \"icon\": \"i555\" }}, {{ \"index\": 1, \"text\": \"{1}\", \"icon\": \"a230\" }}, {{ \"index\": 2, \"text\": \"{2}\", \"icon\": \"a112\" }} ] }}", txtMessage.Text,txtMessage.Text,txtMessage.Text);

try {

var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.153212d2df2b9492a5502dd876eac046/2");

httpWebRequest.Accept = "application/json"; httpWebRequest.Headers.Add("X-Access-Token", authInfo); httpWebRequest.Headers.Add("Cache-Control", "no-cache"); httpWebRequest.Host = "developer.lametric.com";

httpWebRequest.ContentType = "text/json";

httpWebRequest.ContentLength = data.Length;

httpWebRequest.Method = "POST";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))

{

streamWriter.Write(string.Format("{0}", data));

streamWriter.Flush();

streamWriter.Close();

}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))

{

var result = streamReader.ReadToEnd();

}

}

catch (Exception ex)

{

lblErr.Text = ex.Message;

}


1 person likes this
Login or Signup to post a comment