I am trying build the sample code from TLS.
I did add the nuget package GHIElectronics.TinyCLR.Networking.Http. The package shows up in the references.
I added this line at the top:
using GHIElectronics.TinyCLR.Networking.Http;
However I am getting build error like below.
|Error|CS0234|The type or namespace name 'Http' does not exist in the namespace 'GHIElectronics.TinyCLR.Networking' (are you missing an assembly reference?)|TinyCLRApplication|C:\Users\purel\source\repos\hololite\TinyCLR\apps\TinyCLRApplication\HttpsTest.cs|8|Active|
For some reasons, it does not recognize the GHIElectronics.TinyCLR.Networking.Http namespace.
Here is the complete code:
using System.Diagnostics;
using GHIElectronics.TinyCLR.Devices.Network;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Networking;
using GHIElectronics.TinyCLR.Networking.Http;
namespace TinyCLRApplication1 {
class HttpTest {
static void DoTestHttps()
{
var url = "https://www.google.com";
var certificates = Resources.GetBytes(Properties.Resources.BinaryResources.GlobalSign);
X509Certificate[] certx509 = new X509Certificate[] { new X509Certificate(certificates) };
int read = 0, total = 0;
byte[] result = new byte[512];
try
{
using (var req = HttpWebRequest.Create(url) as HttpWebRequest)
{
req.KeepAlive = false;
req.HttpsAuthentCerts = certx509;
req.ReadWriteTimeout = 2000;
using (var res = req.GetResponse() as HttpWebResponse)
{
using (var stream = res.GetResponseStream())
{
do
{
read = stream.Read(result, 0, result.Length);
total += read;
System.Diagnostics.Debug.WriteLine("read : " + read);
System.Diagnostics.Debug.WriteLine("total : " + total);
var page = new String(System.Text.Encoding.UTF8.
GetChars(result, 0, read));
System.Diagnostics.Debug.WriteLine("Response : " + page);
}
while (read != 0);
}
}
}
}
catch { }
}
}
}