Hi with the 4.3.1 framework with posting to a https url work?
A quick how to would be great if that does work.
Thanks
  | ||||||||||||||
Post to HTTPS Rest URL
Started by jhallam, Mar 20 2015 05:41 PM
3 replies to this topic
#1Posted 20 March 2015 - 05:41 PM Hi with the 4.3.1 framework with posting to a https url work?
A quick how to would be great if that does work.
Thanks
#2Posted 28 March 2015 - 03:06 AM Hi jhallam,
http is easy (see sample code below), https is not currently natively supported. (It is on some NetMF devices like the FEZ Mainboards)
If you're doing something with an IoT spin consider a "Service Assisted Communication" approach with a gateway which I cover in my blog
If you're doing a mobile system some modem modules have AT commands for http/https e.g. SIM900.
Certificate management is an issue on embedded devices, so if you control both ends of the connection using XTEA or similar to encrypt the payload may be sufficient. For more detail see my blog
void ServiceGatewayUpdate(string deviceId, string payload)
{
try
{
//WebProxy proxy = new WebProxy("10.0.0.?", 8080);
using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AzureGatewayUrl))
{
byte[] buffer = Encoding.UTF8.GetBytes(payload);
//request.Proxy = proxy;
request.Method = "POST";
request.ContentLength = buffer.Length;
request.ContentType = "text/csv";
request.KeepAlive = false;
request.Timeout = 100;
request.ReadWriteTimeout = 100;
// request body
using (Stream stream = request.GetRequestStream())
{
stream.Write(buffer, 0, buffer.Length);
}
using (var response = (HttpWebResponse)request.GetResponse())
{
Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
}
}
}
catch (Exception ex)
{
Debug.Print(ex.Message);
}
}
@KiwiBryn
blog.devmobile.co.nz
#3Posted 07 August 2015 - 01:30 AM I have some code very similar to this that repeatedly reads a temperature sensor and saves the value to a database. It has the 'keepalive' parameter set to 'true'. I assume this is so it can reuse the HTTP connection. Do you know if this is true? But each time the process reenters this routine it will reexecute the WebRequest.Create command and create a new object. Is this new object being used by the program to communicate with the HTTP object on the server that is still there because of the 'keepalive=true' parameter? #4Posted 11 August 2015 - 10:14 AM Hi alharlow
For my devices the updates were fairly frequent and other posters had commented on running out of sockets if they didn't have request.KeepAlive set to false.
I was planning on doing some testing to confirm as I had initially assumed that the "using" statement forced the release of any resources like TCP sockets.
@KiwiBryn blog.devmobile.co.nz 0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||