Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Post to HTTPS Rest URL


  • Please log in to reply
3 replies to this topic

#1 jhallam

jhallam

    New Member

  • Members
  • Pip
  • 2 posts

Posted 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

 

 



#2 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 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


#3 alharlow

alharlow

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationNebrask USA

Posted 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?



#4 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 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 topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.